FlexGrid for WPF | ComponentOne
In This Topic
    Sorting data
    In This Topic

    Clicking a C1FlexGrid column header sorts the data in ascending or descending order. When the grid is sorted, a triangle displays in the corresponding column to indicate the current sort direction.

    To remove sorting, users can press the Ctrl button while clicking column headers. This removes the sorting applied to the column and causes the data to display in the original order.

    Like grouping, sorting is performed by the ICollectionView used as a data source. The grid detects mouse clicks and defers the sorting to the data source object. You can also sort data directly using code.

    For example, the code below sorts data by name and country:

    C#
    Copy Code
    // start clean
    view.SortDescriptions.Clear();
    
    // sort by name
    view.SortDescriptions.Add(
      new SortDescription("Name", ListSortDirection.Ascending));
    
    // and then by country
    view.SortDescriptions.Add(
      new SortDescription("Country", ListSortDirection.Ascending));
    

    Note that when this code is invoked, the grid automatically shows the data in the new sort order and also shows the triangle sort indicator in the column header.

    You can disable grid sorting by setting the AllowSorting property to false, or disable it for specific columns by setting the Column.AllowSorting property to false. You can also prevent the grid from showing the sort triangle by setting the ShowSort property to false.

    See Also