DataGrid.OnCompareItems

Syntax

OnCompareItems(Sender: Object; Args: IDataGridCompareEventArgs);

Parameters

Sender. The parameter that returns the component that generated the event.

Args. The parameter that enables the user to determine event parameters.

Description

The OnCompareItems event occurs on comparison of column values using custom sorting of the DataGrid component.

Example

Executing the example requires a form, a button named Button1 on the form 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:

DataGrid