DataRelation Parent/Child in DataGridView

  • Thread starter Thread starter Jan Lorenz
  • Start date Start date
J

Jan Lorenz

Hello,

my problem is to show a datarelation between two tables (parent/child) in a
datagridview. It doesn't works. There is always shown only 1 table in the
grid
(in relation of DataMember-settings).

My code is:

DataSet ds = new DataSet();
ds.Tables.Add(parantTable); // Tablename "Parent"
ds.Tables.Add(childTable); // Tablename "Child"

DataColumn dcParent = parentTable.Columns["GroupID"];
DataColumn dcChild = childTable.Columns["GroupID"];

ds.Relations.Add("Rel", dcParent, dcChild, true);

datagridview1.DataSource = ds;

// I already tried:
// datagridview1.DataSource = ds;
// datagridview1.DataMember = "Parent.Rel";
// or
// datagridview1.DataSource = parantTable;

The datagridview1 shows always 1 table only (parent or child), but never
both
with the relation. Whats my mistake?

Thanks
Jan
 
Back
Top