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. Image for the cookie policy date

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

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.


3 Replies

NA Nisha Arockiya A Syncfusion Team 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.

Regards,
Nisha.



IM Irakli Machabeli 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.



NA Nisha Arockiya A Syncfusion Team 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.

Regards,
Nisha.


Loader.
Live Chat Icon For mobile
Up arrow icon