VB.NET ComboBox Datasource

Trying to populate my combobox.  I get an error on "ValueMember".  When I bypass that statement the combobox is filled with "System.Data.DataRow".
    Private _results As New List(Of DataRow)

    Dim SQL As String = String.Empty
    Dim sqlData As New SQLData

    Private Sub PopulateSuppliers()

        Me.cbSupplier.Items.Clear()
        Me.cbSupplier.DataSource = Nothing

        SetSupplierSQL()
        _results = sqlData.SelectStatement(SQL)

        Me.cbSupplier.DataSource = _results
        Me.cbSupplier.DisplayMember = "id"
        Me.cbSupplier.ValueMember = "name"

    End Sub

Open in new window


Any ideas?
LVL 2
CipherISAsked:
Who is Participating?
 
CipherISAuthor Commented:
Below is the solution.  Thanks for your help.
    Private Sub PopulateSuppliers()

        Dim dt As DataTable

        Me.cbSupplier.Items.Clear()
        Me.cbSupplier.DataSource = Nothing

        SetSupplierSQL()
        _results = sqlData.SelectStatement(SQL)

        dt = _results.CopyToDataTable

        Me.cbSupplier.DataSource = dt
        Me.cbSupplier.DisplayMember = "name"
        Me.cbSupplier.ValueMember = "id"

    End Sub

Open in new window

0
 
Dirk StraussSenior Full Stack DeveloperCommented:
I'm not a VB.NET guy (not anymore), but check that the column name is indeed called name.
Me.cbSupplier.ValueMember = "name"

Open in new window

Have a look at this thread: Setting the ValueMember of a combo box is causing an error.
The column name was Com. ID#, but after renaming the column, it worked:
DataTable dt = rwDB.getCommodities();
dt.Columns["Com. ID#"].ColumnName = "ComID";
cboCommodity.DataSource = dt;
cboCommodity.DisplayMember = "Description";
cboCommodity.ValueMember = "ComID";

Open in new window

0
 
NorieVBA ExpertCommented:
Try this.
Me.cbSupplierItems.AddRange(_results.ToArray())

Open in new window

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I've also had instances where I had to set the Display and Value members BEFORE setting the Datasource.
0
 
Ryan ChongCommented:
I get an error on "ValueMember"
what's that error message?

on a separate note, I can do that without error by setting Datasource and then DisplayMember and ValueMember.
0
 
CipherISAuthor Commented:
Made the below changes.  No error but still displaying "System.Data.DataRow" in the combobox.
    Private Sub PopulateSuppliers()

        Me.cbSupplier.Items.Clear()
        Me.cbSupplier.DataSource = Nothing

        SetSupplierSQL()
        _results = sqlData.SelectStatement(SQL)

        Me.cbSupplier.Items.AddRange(_results.ToArray())

        Me.cbSupplier.DisplayMember = "name"
        Me.cbSupplier.ValueMember = "id"

    End Sub

Open in new window

0
 
CipherISAuthor Commented:
Figured out how to resolve the issue and posted the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.