Link to home
Start Free TrialLog in
Avatar of WinkIT
WinkITFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial