Max,
The reason it doesn't work is because you are essentially binding to two
different data sources.
What makes a binding context unique is a combination of the data source
and the data member, both of which have to be the same to share the same
binding context. For your combo box, you have this:
DataSource - ds_myDS.Tables["X"]
DataMember - null
For the textboxes, this is your data source:
DataSource - ds_myDS
DataMember - "X"
Now, while they will both yield the same DataTable, the binding
infrastructure looks at them as two separate binding contexts, and that's
why they don't change.
You need to bind to the same thing, so you need to do this:
cb_myCombo.DataSource = ds_myDS;
cb_myCombo.DataMember = "X";
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS,"Y");
txt_myText2.DataBindings.Add("Text",ds_myDS,"Z");
Or do this:
cb_myCombo.DataSource = ds_myDS.Tables["X"];
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS.Tables["Y"], null);
txt_myText2.DataBindings.Add("Text",ds_myDS.Tables["Z"], null);
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.comwrote in message
news:eK****************@TK2MSFTNGP04.phx.gbl...
>
Can you give me an example because I can't seem to get this working. This
is what I have:
cb_myCombo.DataSource = ds_myDS.Tables["X"];
cb_myCombo.DisplayMember = "A";
txt_myText1.DataBindings.Add("Text",ds_myDS,"Y");
txt_myText2.DataBindings.Add("Text",ds_myDS,"Z");
....
Max
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:Oe**************@TK2MSFTNGP04.phx.gbl...
>Max,
As long as you are binding to the same data table, then you should
have no problem with the textboxes changing when you change the current
record in the combobox. Just make sure that the data table that you bind
everything to has the value that you show in the combobox, as well as the
other values you would show in the textboxes.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Max" <ma******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>>
Hello,
I made a windows form with a combo box and 4 text boxes. All 5 objects
should get their data from a data set which is populated in the form
load method. The combo box has item ids. When the users selects an item
from the combo box I'd like the 4 text boxes to get populated with the
corresponding item information from the same dataset table row that the
combo box is pulling it's info from. Is there an easy way of doing this
besides writing code to query the database based on the combo box id?
(sample code will be appreciated)
Cheers,
Max.