Sort By Display Member Demo

This sample demonstrates a solution for sorting by display members of the foreign-key combo boxes instead of their value members.

Features:

Interactive Features:

SortByDisplayMember screenshot



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:

  1. 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");
  2. Add the foreign table to the engine's SourceList.

            this.gridGroupingControl1.Engine.SourceListSet.Add(ForeignTableName, ForeignTable.DefaultView);
  3. Create and set up a RelationKind.ForeignKeyReference relation.

            GridRelationDescriptor rd = new GridRelationDescriptor();
            rd.Name = "CustomerColDisplay";
            rd.RelationKind = RelationKind.ForeignKeyReference;
            rd.ChildTableName = ForeignTableName;
  4. Set any optional properties on the relation.

            //display column
            rd.ChildTableDescriptor.VisibleColumns.Add("CustomerName"); 
            //sort it for dropdown display.
            rd.ChildTableDescriptor.SortedColumns.Add("CustomerName");
  5. Add a relation descriptor to the MainTableDescriptor.

            td.Relations.Add(rd);
  6. Replace mainTable.Customer with foreignTable.CustomerName.

            string foreignCustomerColInMainTable = rd.Name+"_" + "CustomerName";
            td.VisibleColumns.Insert(CustomerColIndex, foreignCustomerColInMainTable);