ADAdministrator Syncfusion Team December 12, 2004 03:49 AM
Here are two ways you can do it. The first uses the DataView associated with the datasource. It is more flexible in that you can control the sort order and sort multiple columns since you are directly setting the DataView.Sort property. The second method using the grid.Binder.Sort call to do the sort.
//Using the DataView.Sort
CurrencyManager cm = grid.BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager;
if(cm != null)
DataView dv = cm.List as DataView;
if(dv != null)
dv.Sort = "someColName desc";
//using the grid.Binder.Sort
int colIndex = grid.Binder.NameToColIndex("someColName");
int field = grid.Binder.ColIndexToField(colIndex);
ADAdministrator Syncfusion Team December 12, 2004 06:22 AM
I may have missunderstood your question. The above code sorts the record in the DataTable by the values in the column you can choose by name.
If you actually want to display the columns from the datatable by the alpha-order of their column names, then one way to do this is to get the names (which you can do from the DataTable.Columns collection), order these names, and then create GridBoundColumns and add them to the grid.GridBoundColumns collection in the sorted order.