Results 1 to 14 of 14

Thread: Combobox SelectedValueChanged ValueMember

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Cork, Ireland
    Posts
    14

    Combobox SelectedValueChanged ValueMember

    I have a combobox that I have filled with employees. I want to to query my database based on the selected employees ID. I have
    VB Code:
    1. Private Sub ComboBoxSetup()
    2.  
    3.     Dim strDSN As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = _
    4.  " & Application.StartupPath & "\myDB.mdb"
    5.  
    6.     Dim myConnectionString As New OleDbConnection(strDSN)
    7.  
    8.     Dim sql As String = "SELECT EmployeeID, Surname FROM EmployeeDetails WHERE _
    9.  CompanyID=" & CurrentCompanyID & " ORDER BY Surname"
    10.  
    11.     Dim myDataAdapter As New OleDbDataAdapter(sql, myConnectionString)
    12.     Dim myDataSet As New DataSet
    13.  
    14.     myDataAdapter.Fill(myDataSet, "Employees")
    15.  
    16.     Dim myTable As DataTable
    17.     Dim myRow As DataRow
    18.  
    19.     myTable = myDataSet.Tables("Employees")
    20.  
    21.     For Each myRow In myTable.Rows
    22.         cmbSurname.ValueMember = myRow("EmployeeID")
    23.         cmbSurname.DisplayMember = myRow("Surname")
    24.         cmbSurname.Items.Add(myRow("Surname"))
    25.     Next
    26.  
    27.     cmbSurname.SelectedIndex = -1
    28.  
    29. End Sub

    In my SelectedIndexChanged event handler how do I reference the ID corresponding to the selected surname? I have tried a few things.

    VB Code:
    1. Public Sub cmbSurname_SelectedIndexChanged(ByVal sender As System.Object, ByVal _
    2.  e As System.EventArgs) Handles cmbSurname.SelectedIndexChanged
    3.  
    4.      Dim SelectedID as Integer = cmbSurname.ValueMember
    5.      MsgBox(SelectedID)
    6.  
    7. End Sub
    pulls out the ID matching the last employee to be loaded into the combobox

    Wood...Trees...thanks in advance
    Last edited by chakotha; Apr 2nd, 2004 at 06:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width