FAQ & Knowledge Base

Herzlich Willkommen in unserer Wissensdatenbank. Nutzen Sie die Suchfunktion oder durchstöbern Sie unsere Kategorien, um Antworten auf Ihre Fragen zu erhalten.

Kategorien: ShellBrowser Delphi Components | Alle Kategorien anzeigen

Die folgenden Inhalte sind leider nicht auf Deutsch verfügbar.

Sorting custom columns

Frage / Problem

I have added a custom column to the TJamShellList that adds date values for the individual items. The user can sort the column by clicking on the column header, but the column is not sorted by date, but alphabetically. How can I fix this?

Antwort / Lösung

ShellBrowser per default uses an alpha-numerical comparison method on the custom column texts of the items, that unfortunately doesn't respect date values.

You can however custom sort the affected columns by implementing the "OnCompare" event, e.g.:

procedure TMainForm.JamShellList1Compare(Sender: TObject; Item1,
  Item2: TListItem; Data: Integer; var Compare: Integer);
var lDate1, ldate2: TDateTime;
begin
  if JamShellList1.Columns[JamShellList1.SortColumn].Caption = 'Custom date column' then begin
    lDate1 := StrToDateTime(Item1.SubItems[JamShellList1.Columns[JamShellList1.SortColumn].SubItemIndex]);
    lDate2 := StrToDateTime(Item2.SubItems[JamShellList1.Columns[JamShellList1.SortColumn].SubItemIndex]);
    Compare := CompareDateTime(lDate1, lDate2);
  end;
end;