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

Foreign Key Columns in GridGroupingControl

I''m trying to convert some code from GridDataBoundGrid to GridGroupingControl. I haven''t yet been able to figure out how to deal with foreign keys (either for display or for grouping, though Display is far more important). Currently, I do things as per p. 113 of the Grid manual: GridBoundColumn foreignkeycol = grid.Binder.InternalColumns[0]; foreignkeycol.StyleInfo.CellType = "Static"; foreignkeycol.StyleInfo.DataSource = ForeignTable; foreignkeycol.StyleInfo.DisplayMember = "Foo"; foreignkeycol.StyleInfo.ValueMember = "Id"; [I''d also like to be able to get an event before it does the lookup (does QueryStyleInfo get called before it does this mapping?) so I can ensure the value is in my DataTable. But that''s once things are going.] Thanks, Dan

4 Replies

AD Administrator Syncfusion Team April 27, 2004 10:00 AM UTC

Hi Dan, here are some code snippets from the HierarchyView sample that display a foreign key table in a dropdown list: gridColumnDescriptor5.Appearance.AnyRecordFieldCell.CellType = "GridListControl"; gridColumnDescriptor5.Appearance.AnyRecordFieldCell.DataSource = this.shippersDataSet1.Shippers; gridColumnDescriptor5.Appearance.AnyRecordFieldCell.DisplayMember = "CompanyName"; gridColumnDescriptor5.Appearance.AnyRecordFieldCell.ValueMember = "ShipperID"; gridColumnDescriptor5.Appearance.AnyRecordFieldCell.HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Left; gridColumnDescriptor5.MappingName = "ShipVia"; gridColumnDescriptor5.Width = 158; gridRelationDescriptor1.ChildTableDescriptor.Columns.AddRange(new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor[] { new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("OrderID"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("CustomerID"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("EmployeeID"), gridColumnDescriptor5, new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("Freight"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("ShipName"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("ShipAddress"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("ShipCity"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("ShipRegion"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("ShipPostalCode"), new Syncfusion.Windows.Forms.Grid.Grouping.GridColumnDescriptor("ShipCountry")}); In that sample, the foreign key table is in a separate dataset which is the best way to do it. There is also another alternative that is a bit more complicate and I am not sure how well that works for you. We will add support for foreign key relations in future, but the sample gives a first glimpse how this will look like. It is implemented using TableDescriptor_QueryValue and TableDescriptor_SaveValue. It shows data from a foreign table as columns in the records of the main table. This is the sample: ForeignKeyGrid_938.zip Stefan


AD Administrator Syncfusion Team April 27, 2004 07:34 PM UTC

Thank you. What''s the advntage of having it in a separate dataset? (In my application, this is rather difficult.)


AD Administrator Syncfusion Team April 27, 2004 08:37 PM UTC

If both tables are in the same dataset and there is a relation set up between the two tables the ADO dataset tries to join both tables into a dataview and that gets really large. If the two tables have no relation setup between them, then it should normally be ok if the table is in the same dataset. You could give it a try and only if you run into problem then try to separate the table into a different dataset. Stefan


AD Administrator Syncfusion Team April 27, 2004 09:18 PM UTC

Thanks for the warning (I do have a relation between them). So, it will do the join whenever I set a DataSource for a particular column (even if I''m just using a Static cell type?) I think I''ll use QueryValue until there''s full support.

Loader.
Live Chat Icon For mobile
Up arrow icon