Sub OnCompareItems(Sender: Object; Args: IDataGridCompareEventArgs);
Begin
//set of operators;
End Sub OnCompareItems;
The Sender parameter returns the component that has generated the event.
The Args parameter determines event parameters.
The OnCompareItems event occurs on comparison of column values using custom sorting of the DataGrid component.
Executing the example requires a form with the Button1 button and the DataGrid component named DataGrid1.
Class TestForm: Form
DataGrid1: DataGrid;
Button1: Button;
Rows: IDataGridRows;
Sub DataGrid1OnCompareItems(Sender: Object; Args: IDataGridCompareEventArgs);
Var
s1, s2: String;
Begin
s1 := Rows.Item(Args.LeftRow).ColumnValue(0);
s2 := Rows.Item(Args.RightRow).ColumnValue(0);
If s1.Length > s2.Length Then
Args.Compare := 1;
Elseif s1.Length < s2.Length Then
Args.Compare := -1;
Elseif s1.Length = s2.Length Then
Args.Compare := 0;
End If;
End Sub DataGrid1OnCompareItems;
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Begin
Rows := DataGrid1.Rows;
DataGrid1.SortType := ControlSortType.Custom;
DataGrid1.EnableSort := True;
DataGrid1.Columns.Item(0).SortIndex := 0;
DataGrid1.Columns.Item(0).SortAscending := False;
End Sub Button1OnClick;
End Class TestForm;
After executing the example, clicking the button starts custom sorting by the values of the first component column. Rows are ordered in descending value length.
See also: