This sample demonstrates a solution for sorting by display members of the foreign-key combo boxes instead of their value members.
Features:
Setting up a foreign-key reference relation between tables
"Customer Name" displayed in the foreign table where a column named "Customer" is located in the main table
A Customer column with key values that match the values in a column named "Customer ID" in the foreign table
Interactive Features:
Steps to accomplish sorting by display member:
Save the location of the mainTable.Customer column so that it can be swapped after a foreign-table reference is set.
Add the foreign table to the engine's SourceList.
Create and set up a RelationKind.ForeignKeyReference relation.
Set any optional properties on the relation.
Add a relation descriptor to the MainTableDescriptor. Replace mainTable.Customer with foreignTable.CustomerName.
In this sample, a column named "Customer Name" is displayed in the foreign table where a column named "Customer" is located in the main table. The customer column holds key values that match the values in a column named "Customer ID" in the foreign table.
Here are the steps to accomplish this:
Save the location of the mainTable.Customer column so that it can be swapped after the foreign table reference is set.
GridTableDescriptor td = this.gridGroupingControl1.TableDescriptor; td.VisibleColumns.LoadDefault(); int lookUpIndex = td.VisibleColumns.IndexOf("Customer");
Add the foreign table to the engine's SourceList.
this.gridGroupingControl1.Engine.SourceListSet.Add(ForeignTableName, ForeignTable.DefaultView);
Create and set up a RelationKind.ForeignKeyReference relation.
GridRelationDescriptor rd = new GridRelationDescriptor(); rd.Name = "CustomerColDisplay"; rd.RelationKind = RelationKind.ForeignKeyReference; rd.ChildTableName = ForeignTableName;
Set any optional properties on the relation.
//display column rd.ChildTableDescriptor.VisibleColumns.Add("CustomerName"); //sort it for dropdown display. rd.ChildTableDescriptor.SortedColumns.Add("CustomerName");
Add a relation descriptor to the MainTableDescriptor.
td.Relations.Add(rd);
Replace mainTable.Customer with foreignTable.CustomerName.
string foreignCustomerColInMainTable = rd.Name+"_" + "CustomerName"; td.VisibleColumns.Insert(CustomerColIndex, foreignCustomerColInMainTable);