ComponentOne FlexGrid for WinForms
Sorting Multiple Columns
FlexGrid for WinForms Task-Based Help > Sorting Multiple Columns

To sort multiple columns, set each column's Sort property and use the Sort method to sort according to the column settings.

  1. Add the following code to the Form_Load event to set the second column to sort in ascending order and the third column to sort in descending order.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1FlexGrid1.Cols(1).Sort = C1.Win.C1FlexGrid.SortFlags.Ascending
    Me.C1FlexGrid1.Cols(2).Sort = C1.Win.C1FlexGrid.SortFlags.Descending
    

    To write code in C#

    C#
    Copy Code
    this.c1FlexGrid1.Cols[1].Sort = C1.Win.C1FlexGrid.SortFlags.Ascending;
    this.c1FlexGrid1.Cols[2].Sort = C1.Win.C1FlexGrid.SortFlags.Descending;
    
  2. Add the following Sort method to sort according to the settings in columns two and three.

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1FlexGrid1.Sort(C1.Win.C1FlexGrid.SortFlags.UseColSort, 1, 2)
    

    To write code in C#

    C#
    Copy Code
    this.c1FlexGrid1.Sort(C1.Win.C1FlexGrid.SortFlags.UseColSort, 1, 2);
    

This topic illustrates the following:

Your grid will look like the following with the second column sorted in ascending order, then the third column in descending order. In this example, Neon appears before Argon in the Element column since the grid is sorted first by the StandardState column in ascending order, then by the Element column in descending order.