Double binding

M

Massimo

I have a database with two tables, with a foreign relation between them; the
schema is like this:

Table 1 {A, B, C, D, E}
Table 2 {E, F}

E is the primary key for table 2, and is used as a foreign key in table 1.

Now, I have two DataSets (one for table 1 and the other for table 2), and
I'm trying to do some data binding in a winform, but I don't know how to
accomplish what I want; in the form, I have some EditBoxes bound to columns
of the first DataSet, and a ComboBox. I want the ComboBox to get its list of
elements from the second DataSet, and I also want the current selected item
to be bound to column E of the first DataSet, in order to automatically
update the column in the current row.
What is the right way to accomplish this, if there is one?
Thanks

Massimo

P.S.
I don't want code to manually fill the ComboBox and/or change the current
row when the selection is changed; I prefer data bindings, if there is a
good way to use them in this situation.
 
J

Jaga

Hello Massimo,

if you want use DataBinding, you should use only one DataSet. Add both
DataTable to it and bind the tables with a DataRelation.

Your problem is only the ComboBox. If it were a DataGrid, you could do
followings:

myGrid.DataSource = myDataSet;
myGrid.DataMember = "myDataSet.myDataRelation";

But a ComboBox has no DataMember property.
Send a request an Microsoft to extend the ComboBox class, or use a third
party ComboBox, that has a DataMember. (e.g. UltraCombo from Infragistics -
not for free)

Jaga
 
J

Jaga

Sorry, the syntax was falsch. You should do followings:

DataRelation myRelation = new DataRelation("RelationT1T2",

myDataSet.Tables("Table1").Columns("E1"),

myDataSet.Tables("Table2").Columns("E2"));
myDataSet.Relations.Add(myRelation);
myGrid.DataSource = myDataSet;
myGrid.DataMember = "Table1.RelationT1T2";

Jaga
 

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