Dataset question

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

I have a listbox that is bound to a dataset with 1 table that has 4 fields.
The first field is displayed in the listbox.

When I click on an item in the listbox I want to fill in a text box with the
info found in the 3rd field of the "current" row. What is the best way to
do this?

Thanks!
 
On the postback (after a user selects data from the listbox), you can
iterate through the dataset and find the record that matches the one
selected in the listbox. Once the record is found, you can get whatever
field from that record you need.
 
Assuming you are talking about desktop apps.. with a dataSet named myDataSet
which contains myDataTable which is comprised of Field1, Field2, Field3 and
Field4
//old way of doing it
//listBox1.DataSource = myDataTable;
//listBox1.DisplayMember = "Field1";
//listBox1.ValueMember = "Field1";
listBox1.DataBindings.Add("SelectedItem", myDataSet.Tables["myDataTable"],
"Field1");

//Do the same for selectedValue
//now for the textbox

tbWhatever.DataBindings.Add("Text", myDataSet.Tables["myDataTable"],
"Field3");

Now, all you have to do is create a bindingmanagerBase, set it to the form
(or container control's) bindingContext and that should do it for you.
--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Back
Top