GridRowCollection gridRows = this.gridControl1.Data.Rows;
int headerCount = this.gridControl1.Rows.HeaderCount+1 + 1; // 1 extra for column styles info row
int colnum = col + 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];
if (style1 != null)
{
object val1 = style1.GetValue(GridStyleInfoStore.CellValueProperty);
sortArray[n].sortValue = val1;
}
}
}
Array.Sort(sortArray);
//this.gridControl1.Data.SortByColumn(col, (ListSortDirection)this.gridControl1[0, col].Tag);
for (int n = 0; n < rowCount; n++)
{
gridRows[n+headerCount] = sortArray[n].row;
}
public struct GridRowSortItem : IComparable
{
public GridCellCollection row;
public object sortValue;
#region IComparable Members
public int CompareTo(object obj)
{
object val1 = sortValue;
object val2 = obj != null ? ((GridRowSortItem) obj).sortValue : null;
if (val1 == null && val2 == null)
return 0;
else if (val1 == null)
return -1;
else if (val2 == null)
return 1;
else
{
try
{
if (val1 is IComparable && val2 is IComparable)
{
int r = ((IComparable) val1).CompareTo(val2);
//Trace.WriteLine(val1.ToString() + " / " + val2.ToString() + " : " + r.ToString());
return r;
}
}
catch (Exception ex)
{
}
return val1.ToString().CompareTo(val2.ToString());
}
}
#endregion
}
A project with above code is here:
http://www.syncfusion.com/Support/user/uploads/MySort_43078f08.zip
Stefan
>Using grid version 2.1.0.9, I have strange results when performing column sorting of a fairly large grid (125 cols by 3000 rows): the speed of the sort of 2 adjacent columns is wildly different (i.e. the slowest takes 270 times more than the other!). The slow one takes about 1 minute, which is not acceptable.
>The columns are identical, meaning that both contain strings of comparable size.
>
>Then I''ve tried populating the slow sorting column with the same values as the fast sorting one and now the two sorted with equal speed (i.e. fast). I don'' t understand how comes that the speed of the sorting is dependent on the actual strings in the columns to the extent that one is slower than the other by a factor of 270!
>
>I will try to put together a sample, but I''m just curious if anybody had a similar experience and what was done about this.
>
>