[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • Last Modified:

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!


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

1 Solution

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now