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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridControl - Sorting

Thread ID:





48875 Sep 5,2006 08:09 PM UTC Sep 28,2006 09:36 PM UTC WinForms 3
Tags: GridControl
Julie Levy
Asked On September 5, 2006 08:09 PM UTC

Hi -
I was looking improve the performance of sorting large sets of data and followed the instructions in the following forum post (using the referenced sample).

It definitely speeds things up, but it is sorting my float column like strings even though i am setting the CellValueType to Double. When the GridRowSortItem does the compare, it''s of 2 objects and thus the sorting is incorrect.

Any suggestions or other samples on how i can propertly sort different data types?


Administrator [Syncfusion]
Replied On September 6, 2006 03:52 AM UTC

Hi Julie,

The GridControlSort browser sample shows you how to add header-click sorting to your grid. The header cell draws a sort icon to indicate that the column has been sorted in a particular direction.

Here is a path.
[Instal drive]: \Program Files\Syncfusion\Essential Studio\\windows\Grid.Windows\Samples\Quick Start\GridControlSort

Click the syncfusion Browser Sample=>Essetail Studio samples => GridSamples => QuickStart => GridControlSort

Let me know if this helps.

Julie Levy
Replied On September 6, 2006 05:09 PM UTC

Hi Haneef -
Thanks for your quick response.
The sample you are suggesting shows how to do custom sorting for a formula column and uses SortByColumn. I found SortByColumn to be very slow which is why i went with the other example which uses an Array sort. It doesn''t, however, recognize the cellvaluetypes when it does the compare. I found a way to do it by getting the cellvaluetype out using model indexing when building the array, storing it in the GridRowSortItem, and then checking it during the compare. (see code below) This has to be slowing things down so i was just wondering if there was a better way.

public struct GridRowSortItem : IComparable
public GridCellCollection row;
public object sortValue;
public Type valueType;
#region IComparable Members

public int CompareTo( object obj )
int iResult = 0;
object val1 = sortValue;
object val2 = obj != null ? ((GridRowSortItem)obj).sortValue : null;
double double1 = 0;
int int1 = 0;
int int2 = 0;
double double2 = 0;

if (ObjectIsNullOrEmpty( val1 ) && ObjectIsNullOrEmpty(val2))
return 0;
else if (ObjectIsNullOrEmpty(val1))
return -1;
else if (ObjectIsNullOrEmpty( val2 ))
return 1;
if (val1 is IComparable && val2 is IComparable)
if (valueType == typeof( Double ))
double1 = Convert.ToDouble(val1);
double2 = Convert.ToDouble(val2);
iResult = double1.CompareTo( double2 );
else if (valueType == typeof( Int32 ))
int1 = Convert.ToInt32( val1 );
int2 = Convert.ToInt32( val2 );
iResult = int1.CompareTo( int2 );

iResult = ((IComparable)val1).CompareTo( val2 );

//int r = ((IComparable)val1).CompareTo( val2 );
//Trace.WriteLine(val1.ToString() + " / " + val2.ToString() + " : " + r.ToString());
return iResult;
catch (Exception ex)

return val1.ToString().CompareTo( val2.ToString() );


protected virtual void SortData( int columnIndex )
long start = DateTime.Now.Ticks;

GridRowCollection gridRows = this.Data.Rows;

int headerCount = this.Rows.HeaderCount + 1 + 1; // 1 extra for column styles info row
int colnum = columnIndex + 1; // 1 extra for row styles info column
int rowCount = gridRows.Count - headerCount;
GridRowSortItem[] sortArray = new GridRowSortItem[rowCount];
for (int n = 0; n < rowCount; n++)
sortArray[n] = new GridRowSortItem();
GridCellCollection row = gridRows[n + headerCount];
if (row != null)
sortArray[n].row = row;
GridStyleInfoStore style1 = row[colnum];
GridStyleInfo style2 = this.Model[n + headerCount-1, columnIndex];
if (style1 != null)
object val1 = style1.GetValue( GridStyleInfoStore.CellValueProperty );
sortArray[n].sortValue = val1;
sortArray[n].valueType = style2.CellValueType;

Array.Sort( sortArray );

for (int n = 0; n < rowCount; n++)
gridRows[n + headerCount] = sortArray[n].row;

long end = DateTime.Now.Ticks;

//string str = "Column " + columnIndex + " took " + (end - start).ToString( "N0" ) + " ticks";
//System.Diagnostics.Debug.WriteLine( str );

Cursor.Current = Cursors.Default;


Replied On September 28, 2006 09:36 PM UTC

Hello my friends,

I would like to know instead how can I keep the user from sorting the columns.

Sometimes the users need to have the data in the original sequence it is being displayed but some of them sort the data unintentionally and the printouts are messed out.

So, my question is, how to disable the sorting ability of the control.

Any help is much appreciated.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon