Parent child binding question

B

Bob

Got a datagridview with records bound to tableParent. Each time I go to a
new row (single select) in the datagrid view I want a series of textboxes as
well as another datagridview to shwo the realted records. The textboxes are
in tableChild1 and the other datagridview is of tableChild2, Both these
tables have a PK-FK relationship established in the dataset being used. How
can I do this?

Any help appreciated.

Bob
 
A

Aphazel

Actually it's quite simple. One important thing is that all control bindings
must refer to tables and columns indirectly thru dataset. If you bind the
controls directly to particular tables/columns, you'll loose the synchro you
want while browsing tableParent.

You're supposed to name the tables (at least tableParent) and relations, if
they aren't named yet (use TableName and RelationName properties).

' let's say the DataSet object is ds
' for tableParent
parentGridView.DataSource = ds
parentGridView.DataMember = "tableParent_name"

' for tableChild1 each control must have separate binding, eg. binding to
sampleTextBox.Text looks like this:
sampeTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", ds,
"tableParent_name.parent_child2_relation_name.column_name", True))

' for tableChild2
child2GridView.DataSource = ds
child2GridView.DataMember = "tableParent_name.parent_child2_relation_name"

' FOLLOWING IS THE WRONG WAY
child2GridView.DataSource = ds.Tables("tableParent_name")
child2GridView.DataMember = "parent_child2_relation_name"

Hope you find it simple ;)
Aph
 
B

Bob

Thanks Aph

Microsoft should hire you to do their documentation. Then idiots like me
could understand and cut through all the marketing BS and unintelligible
jargon.
Bob
 

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