Problem binding a datatable to a combo box

Posted on 2008-11-10
Last Modified: 2012-08-13
I have a two combo boxes that are bound to data tables using the two procedures below.  

The first populates a combo box with a list of codes for a given project  The second box is populated with a list of items for the selected code in the first box.

The fist box's display member seems to be setting correctly however the value member does not.

As I load the first box the SelectedIndexChanged event fires off as it is being filled and i think this is what is causing the issue.  If i run in debug mode, the cmbActivityCode.SelectedValue is set to "System.Data.DataRowView"

Any help would be appreciated!


Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click

        Dim db As New DBConnection

        Dim dt As DataTable = db.GetCodeList(txtProjectID.Text)


        cmbActivityCode.DataSource = dt.DefaultView

        cmbActivityCode.DisplayMember = "ActivityCode"

        cmbActivityCode.ValueMember = "ActivityCode"


    End Sub

Private Sub cmbActivityCode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbActivityCode.SelectedIndexChanged

        Dim db As New DBConnection

        Dim dt As DataTable = db.GetItemList(txtProjectID.Text, cmbActivityCode.SelectedValue.ToString)


        cmbItemNumber.DataSource = dt.DefaultView

        cmbItemNumber.DisplayMember = "ItemNumber"

        cmbItemNumber.ValueMember = "ItemNumber"


    End Sub

Open in new window

Question by:WinkIT
    1 Comment
    LVL 69

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now