How do I change the selected item in a listbox according to a Comb

G

Guest

How do I change the selected item in a listbox according to a Combox's
selected item on the same form? The Combox is from a different table in the
same dataset as the Listbox uses. Combox's ValueMember is a ID that is a
column in the table that the listbox uses. Is there a way to link these 2's
relation so that when the user changes the selection in the Combox the list
box would automacticall changes to reflect the items that's linked to the
combox selection?

Thanks, Alpha
 
G

Guest

The simplest way is to create a binding between the two with
DataBindings.Add() which is accessible as a property of the control that you
want to automatically update.

A simple example of this would be a ListBox and a ComboBox bound to the same
data, in order to have the SelectedValue in the ListBox be the same as what
the ComboBox has been set to, you would simply do the following:

listBox1.DataBindings.Add("SelectedValue", comboBox1, "SelectedValue");

The above example assumes that the property specified by the ValueMember of
both controls is the same and unique within the list.

Brendan
 
G

Guest

Thank you. I'll give it a try.

Brendan Grant said:
The simplest way is to create a binding between the two with
DataBindings.Add() which is accessible as a property of the control that you
want to automatically update.

A simple example of this would be a ListBox and a ComboBox bound to the same
data, in order to have the SelectedValue in the ListBox be the same as what
the ComboBox has been set to, you would simply do the following:

listBox1.DataBindings.Add("SelectedValue", comboBox1, "SelectedValue");

The above example assumes that the property specified by the ValueMember of
both controls is the same and unique within the list.

Brendan
 

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


Top