Populating a combobox

Hi,

I would like to populate a combobox with a list of customer names, but I need the customer ID associated to that customer linked to the name. The customer ID must not be visible to the user in the windows form.

When the user selects a customer from the list, I need to get the customer ID from the combobox.

I was able to do this in VB6 but I am struggling to get this right in VB2005.

PLEASE HELP!!



Answer this question

Populating a combobox

  • xishan shigri

    The Combobox's DisplayMember is the value shown. It's ValueMember is the value.


  • Pradeep Gupta

    Private Sub OnFormLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

    ' Get the data and

    m_CustomersDataSet = CustomersDataSet.GetCustomers()

    ' Set up the bindings for the combo boxes

    m_CompanyNameCombo.DataSource = m_CustomersDataSet.Customers

    m_CompanyNameCombo.DisplayMember = "CompanyName"

    m_CompanyNameCombo.ValueMember = "CustomerID"

    m_ContactNameCombo.DataSource = m_CustomersDataSet.Customers

    m_ContactNameCombo.DisplayMember = "ContactName"

    m_ContactNameCombo.ValueMember = "Phone"

    End Sub



  • Populating a combobox