Solved

Trying to load a ComboBox using a DataTable?

Posted on 2014-03-12
3
183 Views
Last Modified: 2014-03-17
I have a simple procedure in which I'm trying to assign a DataSource to a ComboBox DataSource. When I look at how many rows were added to the DataSource, the count is correct, however, when I go to select an entry from the ComboBox, all the entry values are "System.Data.DataRowView". Not sure what is causing this. Here is my code:

    Private Sub LoadNewUsersComboBox()
        Try
            Dim tbl As New DataTable
            Dim row As DataRow

            tbl.Columns.Add("commonName")
            tbl.Columns.Add("SAMAccountName")

            For x As Integer = 0 To arrStcLDAP.Count - 1
                row = tbl.NewRow
                row("commonName") = arrStcLDAP(x).commonName
                row("SAMAccountName") = arrStcLDAP(x).samAcctName
                tbl.Rows.Add(row)
            Next

            cmbUserName.DataSource = Nothing
            cmbUserName.DisplayMember = tbl.Columns(0).ColumnName.ToString
            cmbUserName.ValueMember = tbl.Columns(1).ColumnName.ToString
            cmbUserName.DataSource = tbl
            cmbUserName.SelectedIndex = -1

        Catch ex As Exception
            EH.ErrorMessage = "LoadNewUsersComboBox() - " & ex.Message & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

0
Comment
Question by:BlakeMcKenna
  • 2
3 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 39924389
The ColumnName seems to be causing the issue.  Change to this and it should work fine.

            cmbUserName.DisplayMember = tbl.Columns(0).ToString()
            cmbUserName.ValueMember = tbl.Columns(1).ToString()

Open in new window

0
 

Accepted Solution

by:
BlakeMcKenna earned 0 total points
ID: 39924581
actually I figured it out. I had the "Sorted" property set to True. I changed it to false and that fixed it!
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39933775
I found my own problem!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now