Solved

Trying to load a ComboBox using a DataTable?

Posted on 2014-03-12
3
186 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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