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

How to sort columns according to their names?

Thread ID:

Created:

Updated:

Platform:

Replies:

22406 Dec 12,2004 05:58 AM UTC Dec 12,2004 11:22 AM UTC WinForms 2
loading
Tags: GridControl
Rebecca
Asked On December 12, 2004 05:58 AM UTC

I am using GridDataBoundGrid. The columns are dynamically added at each time and should be displayed aftering sorting. Thanks~ Rebecca

Administrator [Syncfusion]
Replied On December 12, 2004 08:49 AM UTC

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);
grid.Binder.Sort(field);

Administrator [Syncfusion]
Replied On December 12, 2004 11:22 AM UTC

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.

CONFIRMATION

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.

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

;