MultiColumn Sorting is one of the most important feature of C1FlexGrid for WinForms. This feature is not offered by many grids, thereby making this control a better choice for the developers.
When implementing MultiColumn Sorting in C1FlexGrid, the values in the column sort themselves depending on the sorting order of the other columns. The values are sorted correctly; however, you would observe that the Glyphs for the previously sorted columns are not retained. Hence, it becomes difficult to determine the sorting order for the other columns.
This blog implementation looks forward to handle this scenario and display Sorting Glyphs for each column on which the sorting has been applied.
Glyphs can easily be added by using the OwnerDraw event of the C1FlexGrid control. This event is fired for each cell and the cell is re-drawn. In this event, we can determine the sorting applied on each column(if any) and assign the corresponding Glyph Image to that header cell.
Following code snippet needs to be added in the OwnerDraw event of the C1FlexGrid :
Private Sub C1FlexGrid1_OwnerDrawCell(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.OwnerDrawCellEventArgs) Handles C1FlexGrid1.OwnerDrawCell If e.Row = 0 Then e.Style.ImageAlign = C1.Win.C1FlexGrid.ImageAlignEnum.RightCenter If C1FlexGrid1.Cols(e.Col).Sort = C1.Win.C1FlexGrid.SortFlags.Ascending Then e.Image = C1FlexGrid1.Glyphs(C1.Win.C1FlexGrid.GlyphEnum.Ascending) ElseIf C1FlexGrid1.Cols(e.Col).Sort = C1.Win.C1FlexGrid.SortFlags.Descending Then e.Image = C1FlexGrid1.Glyphs(C1.Win.C1FlexGrid.GlyphEnum.Descending) End If Else e.Image = Nothing End If End Sub