Add a DataRelation in Designer to Datagridviews

SteveInBeloit

Well-known member
Joined
May 22, 2006
Messages
132
Programming Experience
10+
Hi,
I have a form with two datagridview. I want to add a relation between the two in the dataset so that I can bind the first one to the table, and the second one to the first one based on the relation.
If the relation is set up as a FK in the tables, it is no problem. In the drop down of the second binding source for the datamember property, you can choose the relation.
But I want to add a relation ad design time. I don't see how to add it then so I can have it available to choose in the second binding source.

My Data tab in the toolbox does not have a Relations object.

Any ideas?

Thanks,
Steve
 
Last edited:
Go to the data sources window (by default it shares a tab with the solution explorer etc). I am NOT talking about the data part of the toolbox

EXPAND EVERY NODE in the data sources tree, and i mean every node.. all the children

You will see related tables are repated in the tree.. At the top level, they are bound direct, when nested they are bound via the parent node


So, you have 2 tables, parent/child and a relation
Open data sources window
Drag parent onto the form
Expand parent in the window
Drag the NESTED child not the top level child
Child grid appears bound by default to the parent bind source

More info, see DW2 link in sig, section Displaying Related DAta...
 
Wow! That was WAY too easy. Thanks! The walkthrough in your sig are great, I have been through a couple of them.

IF the relationship does NOT exist between the tables, and you do not want to put a foreign key on that table, can you add the relation from the designer?

Thanks again,
Steve
 
yep

either right click the background and add relation

or click to single highlight the parent table row, and then click the grey square (where the key symbol might appear) to the left and drag out of the datatable, into the grey square of the column you wish to relate.. if you want to make your relation a wiggly line then every click on the background while drawing the marching ants line will put a joint in the line.

sounds fiddly, it is.. click-dragging the white bit normally jsut selects multiple rows of the source table. have a play and youll see what I mean
 
Back
Top