FlexGrid for WinForms | ComponentOne
In This Topic
    In This Topic

    By default, the FlexGrid control lets you sort the grid by any column. You can simply click on the header of a column to toggle between the sorting states, ascending and descending. If you click the column header, it sorts by that column. In this case, the column header shows an upward pointing arrow indicating ascending order. Likewise, if you click the column header once more, that is, the second time, the column sorts in descending order, with the arrow pointing downwards.

    sorting in FlexGrid

    Column sorting is already enabled in the FlexGrid control and by default, the value of AllowSorting property of the C1FlexGrid class is set to Auto. However, you can choose to prevent sorting by setting AllowSorting property to None or simply change the way the columns are sorted through AllowSortingEnum enumeration. The AllowSortingEnum enumeration allow you to choose whether to auto sort columns, sort single column, sort multiple columns, sort column range or just prevent sorting.

    Multi-column Sorting

    FlexGrid supports multi-column sorting that allows you to sort multiple column in different order. It allows you to sort multiple columns at runtime by simply holding the CTRL key and clicking multiple column headers. When you sort multiple columns, the grid shows the sort index in the column header, next to the sort direction glyph.

    multi-column sorting in FlexGrid

    In addition to sorting columns at runtime, FlexGrid also allows you to sort multiple columns programmatically. To do so, you simply need to write a single line of code as demonstrated below. To sort multiple columns, you can set the AllowSorting property to MultiColumn using the AllowSortingEnum enumeration.

    fgrid.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.MultiColumn
    fgrid.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.MultiColumn;

    In case you want to remove sorting from any column at runtime, you can simply hold the CTRL key and click that column's header.