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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
NorieAnalyst Assistant Commented:
Try this.
Me.cbSupplierItems.AddRange(_results.ToArray())

Open in new window

0
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
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
Figured out how to resolve the issue and posted the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.