user279521
user279521

Reputation: 4807

Unable to display records in dropdownList control

I am using VB.Net 2010, and when I run the following code, I get System.Data.DataViewManagerListItemTypeDescriptor displaying in the dropdownlist box

 cmbProdType.DataSource = ds
 cmbProdType.DisplayMember = "ProductType"
 cmbProdType.ValueMember = "ProductCode"

When I hover over the datasource, I can see the correct records. But its not displaying in the dropdownlist control.

Upvotes: 2

Views: 579

Answers (2)

DNR
DNR

Reputation: 3746

Try this:

cmbProdType.DataSource = ds.Tables(0)

Upvotes: 3

dwidel
dwidel

Reputation: 1294

First of all I don't usually bind to a dataset, I bind to the datatable in the dataset, but it looks like you have that working?

Second I set the datasource after I tell it the display and value members.

EDIT:

    Dim ds As New DataSet
    Dim dt As New DataTable("dt")
    dt.Columns.Add("ProductType")
    dt.Columns.Add("ProductCode")

    For i = 0 To 10
        Dim dr As DataRow = dt.NewRow
        dr.Item("ProductType") = ChrW(i + AscW("A"))
        dr.Item("ProductCode") = i
        dt.Rows.Add(dr)
    Next


    cbo.DisplayMember = "ProductType"
    cbo.ValueMember = "ProductCode"


    cbo.DataSource = dt

Upvotes: 2

Related Questions