ID
--
A
B
C
XrefAB table:ID Name
-- ----
A Alpha
B Bravo
C Charlie
TableB:Name Data
---- ----
Alpha 1
Bravo 2
Charlie 3
I have a DataGridView displaying TableA.DataGridView
+-----+ TextBox
| A | +------+
| B | | |
| C | +------+
+-----+
DataSet ds = new DataSet();
OracleDataAdapter adapterTableA = new OracleDataAdapter("Select * from TABLEA", connection);
OracleDataAdapter adapterXrefAB = new OracleDataAdapter("Select * from XREFAB", connection);
OracleDataAdapter adapterTableB = new OracleDataAdapter("Select * from TABLEB", connection);
adapterTableA.Fill(ds, "TableA");
adapterXrefAB.Fill(ds, "XrefAB");
adapterTableB.Fill(ds, "TableB");
DataRelation drA2Xref = new DataRelation("TableAXref",
ds.Tables["TableA"].Columns["ID"],
ds.Tables["XrefAB"].Columns["ID"]);
ds.Relations.Add(drA2Xref);
DataRelation drXref2B = new DataRelation("Xref2TableB",
ds.Tables["XrefAB"].Columns["Name"],
ds.Tables["TableB"].Columns["Data"]);
ds.Relations.Add(drXref2B);
BindingSource xrefBS = new BindingSource();
BindingSource textBoxBS = new BindingSource();
xrefBS.DataSource = ds;
xrefBS.DataMember = "TableA";
textBoxBS.DataSource = xrefBS;
textBoxBS.DataMember = "Xref2TableB";
dataGridView.DataSource = ds;
dataGridView.DataMember = "TableA";
textBox.DataBindings.Add("Text", textBoxBS, "Data");
and this works OK.ID Name
-- ----
A Alpha
B Alpha
C Charlie
Suppose user now selects from the DataGridView row B.Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.