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/
 

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

Similar Threads

Listbox questions 4
Fill dataset incrementally 3
Access Cannot select items in listbox 1
Databinding to a listview 2
Windows XP Listbox with 3 columns, cutting formatted value 0
Access MS ACCESS 2007 2
dataset updates 15
Access MS Access Listbox not saving to bound field 0

Back
Top