This sample demonstrates how to manually specify master-detail relations between three separate tables that have primary key and foreign key columns in common.
Features:
You can manually specify the relations in the grouping engine; however, the data set does not need any data relations. This is the same approach that should be used if you want to set up relationships between independent IList collections.
The following is a sample code snippet that sets up the relationship between the IList collections.
// Manually specify relations in grouping engine. The DataSet does not need to have any DataRelations. // This is the same approach that should be used if you want to set up relationships // between independent IList. RelationDescriptor parentToChildRelationDescriptor = new RelationDescriptor(); parentToChildRelationDescriptor.ChildTableName = "MyChildTable"; parentToChildRelationDescriptor.RelationKind = RelationKind.RelatedMasterDetails; parentToChildRelationDescriptor.RelationKeys.Add("parentID", "ParentID"); // Add relation to ParentTable. engine1.TableDescriptor.Relations.Add(parentToChildRelationDescriptor); RelationDescriptor childToGrandChildRelationDescriptor = new RelationDescriptor(); childToGrandChildRelationDescriptor.ChildTableName = "MyGrandChildTable"; childToGrandChildRelationDescriptor.RelationKind = RelationKind.RelatedMasterDetails; childToGrandChildRelationDescriptor.RelationKeys.Add("childID", "ChildID"); // Add relation to ChildTable. parentToChildRelationDescriptor.ChildTableDescriptor.Relations.Add(childToGrandChildRelationDescriptor); // Register any DataTable / IList with SourceListSet, so that the RelationDescriptor can resolve the name. this.engine1.SourceListSet.Add("MyParentTable", parentTable); this.engine1.SourceListSet.Add("MyChildTable", childTable); this.engine1.SourceListSet.Add("MyGrandChildTable", grandChildTable); this.engine1.SetSourceList(parentTable.DefaultView);