Knowledgebase

status_loader

Sorting custom columns

Question / 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?

Answer / Solution

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;

Need further help getting started?

You did not find what you were looking for? Please contact us so we can provide an answer to your question.

Contact Form