Problem binding a datatable to a combo box

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!

Thanks!


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.BeginUpdate()
        cmbActivityCode.DataSource = dt.DefaultView
        cmbActivityCode.DisplayMember = "ActivityCode"
        cmbActivityCode.ValueMember = "ActivityCode"
        cmbActivityCode.EndUpdate()
    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.BeginUpdate()
        cmbItemNumber.DataSource = dt.DefaultView
        cmbItemNumber.DisplayMember = "ItemNumber"
        cmbItemNumber.ValueMember = "ItemNumber"
        cmbItemNumber.EndUpdate()
 
    End Sub

Open in new window

LVL 2
WinkITAsked:
Who is Participating?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.