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.
Unfortunately, activation email could not send to your email. Please try again.

How to sort columns according to their names?

Thread ID:

Created:

Updated:

Platform:

Replies:

22406 Dec 12,2004 12:58 AM Dec 12,2004 06:22 AM Windows Forms 2
loading
Tags: GridControl
Rebecca
Asked On December 12, 2004 12:58 AM

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

Administrator [Syncfusion]
Replied On 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.

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.

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.

;