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

Can anyone provide an example of sorting on lookup column in DataBoundGrid

Thread ID:





79030 Jan 16,2009 10:13 PM UTC Jan 22,2009 12:48 PM UTC WinForms 3
Tags: GridControl
Irakli Machabeli
Asked On January 16, 2009 10:13 PM UTC

I'm talking about this rubbish example "Sort By DisplayMember Demo".

After spending about half a day I finally realized that there is no real sort on lookup column implementation.
Sample either loads data from xml file that already contains lookup values in
products table or if you turn on remote sql server it uses query that is hidden in resource file (and this query does lookup using sql join)

In both cases sorting is done on data that is already in the DataTable and for this simple davaiew.sort is enough.

Nisha Arockiya A [Syncfusion]
Replied On January 19, 2009 01:07 PM UTC

Hi Irakli,

Thanks for your interest in Syncfusion Products.

Please refer the selection command that queiries the Product table.

this.sqlSelectCommand1.CommandText = @"SELECT Categories.CategoryName, Products.ProductID, Products.ProductName, Products.SupplierID, Products.CategoryID, Products.QuantityPerUnit, Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.ReorderLevel, Products.Discontinued, Suppliers.CompanyName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID INNER JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID";

this.sqlSelectCommand1.Connection = this.sqlConnection1;

Just add the foreign key column to the view of the datatable and when the user sorts the combobox column, you can just redirect the sort behavior to use the foreign key column.

To get the sorting work after selecting the value in the combobox, you could try handling the CurrentCellChanged event and set the new value to the underlying DataRow. Here is some code:

private void gridDataBoundGrid1_CurrentCellChanged(object sender, EventArgs e)
GridDataBoundGrid grid = sender as GridDataBoundGrid;
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;

CurrencyManager cm = BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager;
DataRowView drv = (DataRowView) cm.Current;

if(this.gridDataBoundGrid1[0, cc.ColIndex].Text == "Category")
drv["CategoryName"] = this.gridDataBoundGrid1.CurrentCell.Renderer.ControlText;
else if(this.gridDataBoundGrid1[0, cc.ColIndex].Text == "Supplier")
drv["CompanyName"] = this.gridDataBoundGrid1.CurrentCell.Renderer.ControlText;

Please let us know if this serve your needs.


Irakli Machabeli
Replied On January 20, 2009 01:14 PM UTC

This example is not useful. In this example initial lookup i done on the server side and table has column that contains string represenation of lookup value.
I do not want to add fake column to the underlying table. I just want add column to grid.

Essentially I'm looking for example that properly overrides IBindingList and does custom sorting on lookup value.

Nisha Arockiya A [Syncfusion]
Replied On January 22, 2009 12:48 PM UTC

Hi Irakli,

Thanks for the update.

Your direct Trac incident has been updated on this issue for the same query, Please follow it.

Please let us know any other concerns.



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