TcxCustomCheckListBox.OnCompare Event
Enables you to customize the order in which items are displayed in the sorted checklist box.
Declaration
property OnCompare: TcxCollectionCompareEvent read; write;
Remarks
By default, if sorting is enabled within the checklist box, items are sorted in the alphabetical order of their captions. To customize the sort order, handle the OnCompare event, and return a value indicating the comparison result of two items passed as the AItem1 and AItem2 parameters. The following table details the return values:
Return Value | Meaning |
---|---|
Positive Value | AItem1 should be displayed below AItem2. |
Negative Value | AItem1 should be displayed above AItem2. |
0 | AItem1 is equal to AItem2. The sort order is unchanged. |
Sender specifies the TcxCheckListBoxItems.
The following code sample represents the OnCompare event handler, demonstrating how to sort items by their ascending Tag values.
function <Form>.cxCheckListBox1Compare(ASender: TObject; AItem1,
AItem2: TCollectionItem): Integer;
begin
Result := TcxCheckListBoxItem(AItem1).Tag - TcxCheckListBoxItem(AItem2).Tag;
end;
See Also