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

Perfomance of column sorting

I am sorting on three columns with following code: private void gridControlTerminals_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e) { if(e.MouseEventArgs.Button == MouseButtons.Left && e.RowIndex == 0 && e.ColIndex > 0) { gridTerminalSortColumn(e.ColIndex); } } private void gridTerminalSortColumn(int col) { //If the user presses two times on same column it will //be sorted in opposit direction if( col == lastColSorted ) { if ( newDirection == System.ComponentModel.ListSortDirection.Ascending ) { gridControlTerminals.Data.SortByColumn(col, System.ComponentModel.ListSortDirection.Ascending); gridControlTerminals.Refresh(); //Save the direction newDirection = System.ComponentModel.ListSortDirection.Descending; } else { gridControlTerminals.Data.SortByColumn(col, System.ComponentModel.ListSortDirection.Descending); gridControlTerminals.Refresh(); //Save the direction newDirection = System.ComponentModel.ListSortDirection.Ascending; } } else { gridControlTerminals.Data.SortByColumn(col, System.ComponentModel.ListSortDirection.Ascending); gridControlTerminals.Refresh(); newDirection = System.ComponentModel.ListSortDirection.Ascending; } //Save this columnnr lastColSorted = col; } } When i try to shift direction on the same column it lacks so it wont shift direction every time. My guess is that i dont get the mouseevent when the grid is sorting. I noticed the same problem ocures in the SyncFusion GridControlExample. Is there a faster method of sorting the columns? The problem doesnt ocur when i sort different columns every time... Thanks! Kristian Bang, Denmark

2 Replies

AD Administrator Syncfusion Team March 29, 2004 11:08 AM UTC

You might be able to discourage your user from trying to initiate a new sort before the current sort is completed by putting up a wait cursor around the sort call. this.Cursor = Cursors.WaitCursor; this.gridControl1.Data.SortByColumn(col,(ListSortDirection)this.gridControl1[0, col].Tag); this.Cursor = Cursors.Default; As far as faster sorting, if you have special knowledge of the data, then you might be able to do something faster by writing your own SortByColumn implementation, or maybe calling an overload of SortByColumn that accepts a custom comparer object that makes use of the special knowledge. The grid essentially does an ArrayList.Sort call. We will look at the default sort action to see if there is something we can do to speed it up.

AD Administrator Syncfusion Team March 30, 2004 09:56 AM UTC

Isn''t it a bit weird that it is fast enough when i choose to sort a different cloumn every time? I have strings in all three columns so i doubt i can do it faster than an array.Sort()... Until i find a way to get more stability i''ll only sort ascending and not shift direction. Kristian

Live Chat Icon For mobile
Up arrow icon