DataBinding to a combo box.

S

Sharat Koya

Hi I have two tables...

DataSources(id, Type, Name)
DataSourcesTypes(id, TypeDescription)

DataSourcesTypes contains lookup field data that will populate the Type
field in the DataSource table.

I would like to setup a comboBox with the following...
DisplayMember = DataSourcesTypes.TypeDescription
ValueMember = DataSources.Type

The ultimate effect being a form that displays the description in a combo
box but is altering the ID field in the dataSource table for the particular
dataSource being edited.

I understand that a relationship should be setup but I cannot get it to work
?

thanks for any time on this

Sharat Koya
 
G

Guest

Sharat,

No, you don't need to mess with relationships at all.

First, set the DataSource and members of your Combo:

MyCombo.DataSource = DataSourcesTypes;
MyCombo.DisplayMember = "TypeDescription";
MyCombo.ValueMember = "id";

Then, bind the Combo to your other table:

MyCombo.DataBindings.Add("SelectedValue", DataSource, "id")

That should do the trick.

~~Bonnie
 
S

Sharat Koya

Ah thanks, worked a treat.

Bonnie Berent said:
Sharat,

No, you don't need to mess with relationships at all.

First, set the DataSource and members of your Combo:

MyCombo.DataSource = DataSourcesTypes;
MyCombo.DisplayMember = "TypeDescription";
MyCombo.ValueMember = "id";

Then, bind the Combo to your other table:

MyCombo.DataBindings.Add("SelectedValue", DataSource, "id")

That should do the trick.

~~Bonnie
 

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

Top