Help with assigning a value to a Combobox selection

maynard

Member
Joined
Nov 17, 2009
Messages
15
Programming Experience
Beginner
I have a combobox with multiple names. When I select one of the names from the combobox I want to diplay a value(number) instead of the name itself. How could I do that?
 
Hi maynard,

this is also one of my problems, i'm glad that you have figured it out. by the way, is your combobox binded to dataset or you are populating the records programatically from a table in the database? if you are using the later, then how do you populate the description and the corresponding values at the same time...? thanks for sharing.
 
Hi tnr64,

For me I was trying to select a name and then have a value associated with that name diplay in a label. This was the solution to my problem.
BTW: I was populating the names programmatically.

Option Strict On

Public Class Form3

Private intExtension As Integer

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Me.ComboBox1.Items.Add("Smith, Joe")
Me.ComboBox1.Items.Add("Jones, Mary")
Me.ComboBox1.Items.Add("Arhed, Joel")
Me.ComboBox1.Items.Add("Lin, Sue")
Me.ComboBox1.Items.Add("Li, Vicky")
Me.ComboBox1.SelectedIndex = 0


End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

If ComboBox1.SelectedItem Is "Smith, Joe" Then
intExtension = 3388
ElseIf ComboBox1.SelectedItem Is "Jones, Mary" Then
intExtension = 3356
ElseIf ComboBox1.SelectedItem Is "Arhed, Joel" Then
intExtension = 2366
ElseIf ComboBox1.SelectedItem Is "Lin, Sue" Then
intExtension = 1144
ElseIf ComboBox1.SelectedItem Is "Li, Vicky" Then
intExtension = 4320
End If

lblPhoneNumber.Text = "(555) 555- " & intExtension.ToString

End Sub
End Class


There probably is an easier way but this worked for my situation.
 
Back
Top