We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

complex sorting

Is there a way to do a complex sort by clicking on ONE column header. As an example: I have 4 columns in my grid and I click on the fourth column header. I want the grid to sort by column 4 (primary), column 1 and column 2. If I click on column 3 header I want the grid to sort by column 3, column 1, column 2. Brian

7 Replies

AD Administrator Syncfusion Team February 18, 2003 09:18 PM UTC

Multicolumn sorting is not currently directly supported in Essential Grid. We will improve the sorting support in a future release. It would be possible to do such sorting on the underlying datasource. One simple example would be if the grid's datasource is a datatable. Then you could set the Sort property on the DataTable.DefaultView. This Sort property handles multiple columns.

IP Ivan Pelly February 19, 2003 03:39 PM UTC

Along the same lines, what would be the best way to 1) disable the default "double-click to sort" behavior, and 2) place my own graphic in the header, in the same way that the built-in sort capability does? Thanks!

AD Administrator Syncfusion Team February 19, 2003 11:07 PM UTC

You can turn off the default sorting using the GridDataBoundGrid.SortBehavior property. To do your own sorting and get the sort header, you can look at the Grid\Samples\In Depth\GridControlSort sample. It shows one way to do the sort headers.

IP Ivan Pelly February 24, 2003 01:48 PM UTC

I found an example in \Grid\Samples\Quick Start\GridControlSort\VB, but it wasn't obvious how the up/down graphic in the header was being created. What's the recommended way to draw my own graphic in the header? Thanks!

AD Administrator Syncfusion Team February 24, 2003 03:35 PM UTC

Sorry about the wrong folder. The sore header is being drawn by the ColumnHeaderCell celltype. That is why the code keeps switching the celltype from Header to ColumnHeaderCell. If you want to draw your own sort header, probably the simplest way is to use the AferDrawCell event, and then draw whatever you want there using the event arguments which include the bounds, the Graphics object, etc. Now, this event requires that you have wheich is available for download from your support homepage. Here is a snippet that you can add to the GridControlSort sample that will just display the sort headers red and blue. You would want to draw your bitmap or whatever....
Private Sub gridControl1_AfterDrawCell(sender As Object, e As Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs)
   If e.ColIndex > 0 And e.RowIndex = 0 Then
      If Me.gridControl1(0, e.ColIndex).CellType = "ColumnHeaderCell" Then
         If CType(Me.gridControl1(0, e.ColIndex).Tag, ListSortDirection) = ListSortDirection.Ascending Then
            e.Graphics.FillRectangle(Brushes.Blue, e.Bounds)
            e.Graphics.FillRectangle(Brushes.Red, e.Bounds)
         End If
      End If
   End If
End Sub 'gridControl1_AfterDrawCell    

IP Ivan Pelly February 24, 2003 06:49 PM UTC

Thanks! Does the column type have to be ColumnHeaderCell for this to work?

AD Administrator Syncfusion Team February 24, 2003 09:58 PM UTC

Not necessarily. But somehow you must determine whether the column header being drawn is the particular column that needs to have the sort header. In the GridControlSort sample, testing for ColumnHeaderCell is how to do this.

Live Chat Icon For mobile
Up arrow icon