Solved

Trying to load a ComboBox using a DataTable?

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

Independent Software Vendors: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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