[]
        
(Showing Draft Content)

C1.Win.C1FlexGrid.C1FlexGridBase.Sort

Sort Method

Sort(SortFlags, int)

Sorts the grid contents based on a column.

Declaration
public virtual void Sort(SortFlags order, int col)
Parameters
Type Name Description
SortFlags order

SortFlags value that specifies the sort direction and options.

int col

Column to sort on.

Remarks

Sorting works differently depending on whether the grid is bound to a data source or not.

In bound mode, the grid passes the sort request to the underlying data source object. In this case, the sort settings remain in effect as the grid data changes. Editing values in the sort column will cause the data source to re-sort the data, and grid will show the changes automatically. This is equivalent to setting the Sort property on a DataView object for example.

In unbound mode, the Sort method sorts the data that is currently stored in the grid. Changing the data after it has been sorted will not automatically update the sort.

When the grid is bound to a new data source, it inherits the sort settings currently applied to the new data source object. Because of this, calling Sort immediately before setting the DataSource property has no effect on the grid.

In unbound mode, the grid uses a stable sorting algorithm. This means that the sorting keeps the relative order of records when the sorting key is the same. For example, if you sort a list of files by name, then by extension, the list will still be sorted by name within each extension group.

The grid recognizes two types of row: regular rows which contain data, and node rows which are used to group data. The Sort method only sorts regular rows; it does not affect node rows at all. To sort nodes, use the Sort(int, SortFlags, int, int) method in the Tree property or the Sort(SortFlags, int, int) method in the Node class.

Sort(SortFlags, int, int)

Sorts the grid contents based on a column range.

Declaration
public virtual void Sort(SortFlags order, int col1, int col2)
Parameters
Type Name Description
SortFlags order

SortFlags value that specifies the sort direction and options.

int col1

First column in the range.

int col2

Last column in the range.

Remarks

When you sort multiple columns, the same sorting options are applied to each column, starting from the leftmost column in the range and proceeding to the right.

To sort multiple columns using a different sorting order for each, you can either call the Sort(SortFlags, int) method multiple times or set each column's Sort property and call the Sort(SortFlags, int) method including the UseColSort flag in the order parameter.

Sort(SortFlags, CellRange)

Sorts a range of cells in the grid.

Declaration
public virtual void Sort(SortFlags order, CellRange rg)
Parameters
Type Name Description
SortFlags order

SortFlags value that specifies the sort direction and options.

CellRange rg

CellRange object that specifies the range of cells to sort.

Remarks

When you sort multiple columns, the same sorting options are applied to each column, starting from the leftmost column in the range and proceeding to the right.

To sort multiple columns using a different sorting order for each, you can either call the Sort(SortFlags, int) method multiple times or set each column's Sort property and call the Sort(SortFlags, int) method including the UseColSort flag in the flags parameter.

Sort(int, int, IComparer)

Sorts a group of rows using the specified comparer.

Declaration
public virtual void Sort(int rowStart, int rowCount, IComparer comparer)
Parameters
Type Name Description
int rowStart

First row in the sort range.

int rowCount

Number of rows in the sort range.

IComparer comparer

An IComparer object that compares Row objects.

Remarks

The IComparer interface has a single method called Compare(object, object) that takes two objects as arguments (in this case, they will be Row objects) and returns -1, 0, or +1. For more details, see the documentation for IComparer.

Custom sorting can only be used when the grid is in unbound mode.

Sort(IComparer)

Sorts the grid using the specified comparer.

Declaration
public virtual void Sort(IComparer comparer)
Parameters
Type Name Description
IComparer comparer

An IComparer object that compares Row objects.

Remarks

The IComparer interface has a single method called Compare(object, object) that takes two objects as arguments (in this case, they will be Row objects) and returns -1, 0, or +1. For more details, see the documentation for IComparer.

Custom sorting can only be used when the grid is in unbound mode.