Binding to a combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I wanted to know if anyone has any examples of how i can bind a combobox to a datatable. I have found example for how to do this for a textbox but not for a combobox.

Can anyone help
 
You can do it basically two way.. 1) use a datareader and while(dr.Read){
myComboBox.Items.Add(dr(0).GetString());
}

This techincally isn't bound but you populate using a database query.

The other method is to set the DataSource to a given datatable, set the
DisplayMember to the name of the field( Set the DataSource first so you only
have to reference the fieldname) that you want to be shown in the combobox,
so the ValueMember to the name of the field that you want the selectedValue
to be equal to.
X said:
Hi,

I wanted to know if anyone has any examples of how i can bind a combobox
to a datatable. I have found example for how to do this for a textbox but
not for a combobox.
 

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

Back
Top