Skip to main content

TcxCustomShellListView.OnCompare Event

Occurs when two items are compared when sorting the shell list view.

Declaration

property OnCompare: TcxShellCompareEvent read; write;

Remarks

By default, items within the shell list view are sorted so that the corresponding folder objects precede file objects. Then, both folder objects and file objects are sorted independently in alphabetical order. The OnCompare event is fired each time two shell items are compared to determine their relative position within the list.

Handle the OnCompare event to customize the order in which the items will be displayed in the shell list view. The shell items being compared are passed as the AItem1 and AItem2 parameters. Set the ACompare parameter to specify the order in which these shell items will be displayed.

All the possible values of the ACompare parameter are listed in the following table.

Value Description
0 The shell items are the same.
A negative value AItem1 precedes AItem2.
A positive value AItem2 precedes AItem1.

The following code snippet demonstrates how to reverse the default order of shell items within the shell list view.

procedure TForm1.cxShellListView1Compare(Sender: TObject; AItem1, AItem2: TcxShellFolder; out ACompare: Integer);
begin
  // The default sort order
  if AItem1.IsFolder = AItem2.IsFolder then
  begin
    ACompare := CompareStr(AItem1.DisplayName, AItem2.DisplayName);
    // The default sort order
    if not (AItem2.IsFolder) then
      if (sfscLink in AItem2.StorageCapabilities) <> (sfscLink in AItem1.StorageCapabilities) then
        if (sfscLink in AItem2.StorageCapabilities) then
          ACompare := -1
        else
          ACompare := 1;
  end else
    // Folders always precede files
    if AItem1.IsFolder then
      ACompare := -1
    else
      ACompare := 1;
  // Reversing the sort order
  ACompare := -ACompare;
end;
See Also