469,604 Members | 2,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,604 developers. It's quick & easy.

Parent-Child Relation in DataGrid

I have a data grid called Files, which has some columns like FileName, Col1,
Col2, ... , Col8. Then i have a combobox which allows user to select from
Col1 to Col8 and based on this selection, i generate a report from data in
grid Files.
It displays like (e.g. is Col1 is selected):
Col1 Count
Val1 x
Val2 y

This data i display in another datagrid called Data. And under each row in
this grid, i want to show related records. So, when i expand row with Val1,
all rows from Files grid which has Val1 as value for Col1 should be displayed.
To achieve this, i created relation between first column (or selected
column, i.e. Col1 here) of the 'Data' grid and the selected column (e.g. Col1
here) of 'Files' grid. Here is the code for the same:
tblData.DataSet.Relations.Add("Details",tblData.Co lumns[cat],tblFiles.Columns[cat])

This works perfectly. Now, the problem is when i change selection in
comboxbox to say Col2 and try to recreate the rows in the 'Data' grid, it
I used clear method on datatable for it to clear rows, but it gives foreign
key constraint violation says child table has records in it.
So, i tried removing the relation while recreating the datatable by doing:

Doing this, The watch window shows me that relationship is removed, but
still i get the same error. I tried clearing ChildRelations and
ParentRelations as well for the datatable but of no use.
Q1. Am i missing something here? What else i need to do to remove a

I did a workaround for this by setting tblData.DataSet.EnforceConstraints =
false. It did the work but I am still clueless how can i remove a


This is not all... I have some more problems after doing this workaround.. :-(
Now after recreating the 'Data' table, it correctly shows report on the
selected column. And to create different relation now, i do following:
tblData.DataSet.Relations.Add("Details",tblData.Co lumns[cat],tblFiles.Columns[cat]);

However, when i expand one of the rows to see its child rows, it still
refers to old relation. e.g. Now i select Col2 from dropdown, it displays
'Data' as:
Col2 Count
Val1 x
Val2 y

If i expand row with Val1, it still shows rows from Files table which has
Val1 as value of Col1 and NOT Col2. Basically last created relationship is

I could do a workaround for this as well, by adding everytime relationship
with a new name. So, instead of doing this:
tblData.DataSet.Relations.Add("Details",tblData.Co lumns[cat],tblFiles.Columns[cat]);
i do now:
tblData.DataSet.Relations.Add(cat + "

Q2. It works perfectly fine now, but still no idea what is wrong with
original code.


Bear with me... There is one more problem now, last one... :-(
Q3. Now on expanding the child rows, i want to get the selected child row.
How to get the selected child row? I am able to find the selected parent row
but have no idea what should be done to get selected child row. Please help.
Thanks for your patience,

May 23 '06 #1
0 2620

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Zürcher See | last post: by
2 posts views Thread by Jeronimo Bertran | last post: by
6 posts views Thread by Ray Schumacher | last post: by
2 posts views Thread by Steven | last post: by
4 posts views Thread by Andrew | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.