IDataGridCompareEventArgs.Compare

Syntax

Compare: Integer;

Description

The Compare property determines whether sorting is executed.

Comments

One of the following values must be set for the property:

Example

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 click the button, custom sorting by the values of the first component column is implemented. Rows are ordered in descending value length.

See also:

IDataGridCompareEventArgs