ComboBox add item problem

G

Guest

Hi,

I would like to populate some data (4 records) to a ComboBox from Datatable
with an empty row as first row.
Here is what I did...
\\\
Dim dr as datarow

dr = Datatable1.NewRow
dr("ColumnName1") = ""
dr("ColumnName2") = ""
ComboBox1.Items.Add(dr)
For Each dr In Datatable1.rows
ComboBox1.Items.Add(dr)
Next
ComboBox1.ValueMember = "ColumnName1"
ComboBox1.DisplayMember = "ColumnName2"
///

However, when I run it, I only got 5 row of "System.Data.DataRow"
I did exactly the same thing on the other form before but it worked.
Am I missing something?

Please help and thanks in advance.
 
C

Cor Ligthert [MVP]

Kent,

A combobox combines the possibilitiy of a itemcollection and a datasource.
They both are in the combobox.

Probably you can try this,
Dim dr as datarow
dr = Datatable1.NewRow
dr("ColumnName1") = ""
dr("ColumnName2") = ""

DataTable.Rows.Add(dr)
datatable1.defaultview.sort = "ColumnName1"
Combobox1.datasource = datatable1.defaultview ' the last is default
ComboBox1.ValueMember = "ColumnName1"
ComboBox1.DisplayMember = "ColumnName2"

I hope this helps,

Cor
 

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