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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

79030 Jan 16,2009 05:13 PM Jan 22,2009 07:48 AM Windows Forms 3
loading
Tags: GridControl
Irakli Machabeli
Asked On January 16, 2009 05:13 PM

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 08:07 AM

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.


Irakli Machabeli
Replied On January 20, 2009 08:14 AM

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 07:48 AM


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.


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.

;