Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to load a ComboBox using a DataTable?

Posted on 2014-03-12
3
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

705 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