Fairly new to the VB.NET world, but a long time Access and FoxPro programmer.
I'm trying to do something that was extremely easy in Access, but can't believe it is this difficult in VB.NET.
I populated a combobox with values from a mySQL table. I want to return a hidden value from the combobox (Username), but the values that are being displayed are the full names (Firstname and Lastname). So the user selects the full name, but never sees the Username.
I've searched many different sites, and have seen examples that involve creating classes, and other complicated ways of doing it.
This site explains what I am trying to do, where you select a City Name from the combobox, and it returns the zipcode.
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/701a38fd-47e2-47a8-81a0-0884e6fbb1c7
However, the ValueMember/SelectedValue doesn't seem to work for me, or I am not understanding how it is used.
Anyone with any help, or even a link showing my how this is done? I am just not finding the right info on my own.
Thank you so very much.
Private Sub FillComboBox()
Dim sqlQRY As String = "SELECT Lastname, Firstname, Username FROM user"
'Create connection
Dim conn As MySqlConnection = New MySqlConnection(Global_ConnectionString)
Try
' Open connection
conn.Open()
Dim cmd As MySqlCommand = New MySqlCommand(sqlQRY, conn)
'create data reader
Dim rdr As MySqlDataReader = cmd.ExecuteReader
While (rdr.Read)
cboUsernames.Items.Add(rdr("Lastname") & ", " & rdr("Firstname"))
cboUsernames.ValueMember.Equals(rdr("Username"))
End While
Catch ex As MySqlException
MessageBox.Show("Error: " & ex.ToString)
Finally
' Close connection
conn.Close()
End Try
End Sub
Private Sub cboUsernames_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboUsernames.SelectionChangeCommitted
TextBox1.Text = cboUsernames.SelectedValue
End Sub