Populating a combobox from a table

  • Thread starter Thread starter Nicolae Fieraru
  • Start date Start date
N

Nicolae Fieraru

Hi All,

Could somebody provide me step by step instructions of how to populate a
combobox with values from a table (any table from northwind.mdb will do).
What I have done is:
- I added on the form combobox
- I added an oledbConnection which I set to point to the Northwind.mdb
database
- I added an oledbDataAdapter
- I generated a dataSet

Then I setup the data properties of ComboBox (DataSource =
dataSource1.MyTable, DisplayMember = MyField, ValueMember = MyIdField)

After I build the program, when I drop down the combobox, there are no items
in it. What am I missing?
I tried to run the sample program ComboBoxBinding provided by Microsoft in
"SDK\v1.1\QuickStart\winforms\samples\" but when I try to run it, it raises
an error.

Regards,
Nicolae
 
Nicolae,

I cannot see the names you use, so probably (accoording partially to your
code)

\\\
OleDb.OleDbDataAdapter1.Fill(DataSource1)
combobox1.DataSource = DataSource1.MyTable;
combobox1.DisplayMember = "MyDisplayMember";
combobox1.ValueMember = "MyFieldId";
///

I hope this helps?

Cor
 
Hi Cor,

Thank you very much for your tips. It solved my problem. I figured out what
was wrong. On the same form I had a stringgrid and for that one I used the
command:

oleDbDataAdapter1.Fill(dataSet1, "MyField");

While it worked for the stringgrid, it didn't work for the combobox, which
required

oleDbDataAdapter1.Fill(dataSet1);

Regards,
Nicolae
 
Back
Top