saving the sort

Hi,

I was wondering if there is a way to grab the way a grid has been sorted. Currently, when i clear out the grid using grid.GridBoundColumns.Clear(); the sort also gets cleared out. Can I grab how the grid is sorted, clear out the grid, and redraw the new grid with the same sort?

Thanks,
Charlie

4 Replies

SA Saravanan A Syncfusion Team May 8, 2007 07:11 PM UTC

Hi Charlie,

Please refer to the following forum threads that will help you to get the sorted order.

http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=36183
See the last thread in this forum.http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=12261

Using these information you can reapply the same sorting, programmatically after changing the datasource.
Here is the code snippet to apply sorting programmatically.

CurrencyManager cm = this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource,
this.gridDataBoundGrid1.DataMember] as CurrencyManager;
if(cm != null)
{
int colIndex = this.gridDataBoundGrid1.Binder.ColIndexToField(2);
string colName = this.gridDataBoundGrid1.Binder.InternalColumns[colIndex].MappingName;

DataView dv = cm.List as DataView;
dv.Sort = string.Format("[{0}] DESC", colName);
}
}

Best Regards,
Saravanan


CM Charlie Mao May 8, 2007 08:01 PM UTC

Hi Saravanan,

Thanks for the reply. This code snippets seems to apply the sort programmatically for the second column descending. What if the user changes the sort to another column, can you catch that change and apply it programmatically.

Charlie


SA Saravanan A Syncfusion Team May 9, 2007 01:14 AM UTC

Hi Charlie,

Please refer to the following sample, in which the sorting order is retained while reinitializing the datasource.

Sample: http://websamples.syncfusion.com/samples/Grid.Windows/F60590/main.htm

Best Regards,
Saravanan


CM Charlie Mao May 9, 2007 08:13 PM UTC

Hi Saravanan,

Thank you so much. This worked great.

Charlie

Loader.
Up arrow icon