DataRelation Parent/Child in DataGridView


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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top