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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridControl Sorting ComboBox column

Thread ID:





10660 Feb 9,2004 05:48 PM UTC Feb 10,2004 04:32 PM UTC WinForms 6
Tags: GridControl
Administrator [Syncfusion]
Asked On February 9, 2004 05:48 PM UTC

I have a non databound grid control where one of the columns is a combobox. I have sorting enabled on the grid control and when I sort the column that is the combobox it sorts by the valuemember not the displaymember. Is there anyway to specify the sorting for this or override it for this specific column? I am using version currently and don''t think I will be able to update on this release.

Administrator [Syncfusion]
Replied On February 9, 2004 09:30 PM UTC

I am not sure when it was added, but the SortByColumn now has an overload that takes an IComparer object that lets you do custom sorting. Below is a sample that shows how you can use this interface to sort a foreign key combo column by the Display Member instead of the value member. SortwithComparer_6414.zip

Administrator [Syncfusion]
Replied On February 10, 2004 01:04 PM UTC

Well it is not the release I am on. I get the no overload method takes 4 parameters message. I am running

Administrator [Syncfusion]
Replied On February 10, 2004 01:56 PM UTC

If you cannot use the updated grid, then I think you would have to write the sort routine yourself. Then instead of calling this.gridControl1.Data.SortByColumn(col,(ListSortDirection)this.gridControl1[0, col].Tag, 0, cc); you would call your routine. In your sort routine, you can use whatever technique you want to sort things. It would take a little coding, but can be done. Depending on the size of the grids involved, you might just be able to use grid.Rows.MoveRange to move the rows around. More efficiently, you could use an index array, and just move the indexes during the sorting, and then rearrange the grid once after the sorting is complete. There are many other possibilties as well.

Administrator [Syncfusion]
Replied On February 10, 2004 02:43 PM UTC

Well call me lazy but I upgraded to the release which has the Comparer ability in it. However the sample you sent me makes the assumption that the row number matches the column called id, which in my case is not true. So I don''t see how you can get the text value of the column using this sample (the text in the GridStyleInfo reports as the valuemember in text not the displaymember).

Administrator [Syncfusion]
Replied On February 10, 2004 03:35 PM UTC

If your database is not set up to easily access the other fields in the selected item, then you will have to add code to find the right selected item. Below is some code that uses a dataview to do this, but there are other options as well. (You could even loop through the DataTable looking for the proper row. Or, if you set the id up as a primary key, you could use Datatable.Find.))
public class ComparerClass : IComparer
	private DataTable dt;
	private DataView dv;
	public ComparerClass(DataTable dt)
		this.dt = dt;
		this.dv = new DataView(dt, "", "", DataViewRowState.CurrentRows);

	public int Compare(object x, object y)
		GridStyleInfo styleX = new GridStyleInfo(x as GridStyleInfoStore);
		GridStyleInfo styleY = new GridStyleInfo(y as GridStyleInfoStore);
		string sx = "";
		string sy = "";

		dv.RowFilter = string.Format("[id] = {0}", styleX.CellValue);
		if(dv.Count > 0)
			sx = dv[0]["color"].ToString();

		dv.RowFilter = string.Format("[id] = {0}", styleY.CellValue);
		if(dv.Count > 0)
			sy = dv[0]["color"].ToString();
		return sx.CompareTo(sy);

Administrator [Syncfusion]
Replied On February 10, 2004 04:32 PM UTC

Thanks. That was exactly what I ended up doing, it is not very quick so I put in an hour glass during the sort, but it is good enough.


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon