Datagrid: Child of many parents

G

Guest

How do you assign a child datagrid which have more than one parent?

When you have a parent and child datagrid pair, you can assign the child
datagrid using:

DataSet11.Relations.Add("ParentChildRelationshipName", _
DataSet11.Tables("ParentTable").Columns("FieldName"), _
DataSet11.Tables("ChildTable").Columns("FieldName"))

DataGrid2.DataSource = DataSet11
DataGrid2.DataMember = "ParentTable.ParentChildRelationshipName"

BUT, now I have multiple parent datagrids, each with a relationship to one
child table. How do I set the DATAMEMBER property then?
 
W

W.G. Ryan - MVP

Paul - I have grappled with this and run into a lot of dead ends using
databinding. If you have multiple parent tables and try using the
databindings, I've not found anything to work. Please note that I'm not
saying that there isn't a way directly, but I can say that I've tried quite
a bit of approaches and not found success directly. Essentially what I did
was (and I had two comboboxes which were parents and datagrid that had the
intersection of them), when I selected the lefthand combobox, I trapped the
selectedIndexchanged event and then used GetChildRows to populate the grid.
Then when they clicked in the grid,I would look at the row, use
DataTable.Select to grab an array of parent rows (although GetParentRows is
probably a better approach) and then populated them accordingly. This was a
bit intricate in that I had to trap events from all three controls in order
to get the behavior that I wanted. If I didn't need to be able to look up
values based on eitehr of the parents though, I wouldn't have needed to do
this. In Sahil Malik's new book he has a good example of using Many-To-Many
relationships (I don' have it in front of me, but I believe it's chapter 8.
You can get the source code here
http://www.apress.com/book/supplementDownload.html?bID=10002&sID=2923
although I would HIGHLY recommend buying the book, it's truly superb) which
is essentially what this is if I undersatnd you correctly, but that entails
using two parents, If you had more, it may or may not work. Sahil is pretty
frequent in this ng though. You may want to drop Sahil an email - his blog
is here and there's a contact link http://codebetter.com/blogs/sahil.malik/
 
G

Guest

Thanks for your trouble WG! I appreciate the effort - I thought I was alone
in this battle!

The only real reason I like using the relationships, is because the moment
you add a new child record, all the columns which relates to the parents, are
automatically populated for you and you can hide these from the user.

What I ended up doing was to use the convenient relationship method with the
first parent to populate my first column of my child grid automatically and
then fake the rest of the relationships by programmatically adding in the
other parent fields.

It is a bit of nuisance to code all of this and just thought there might be
a shortcut.

Thank again
 

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