Help with .Net combo box
I have a combo box on a form called cboName, already populated with nine names. Nothing is visible in the text portion of the combo box yet. I only want the combo box enabled if the logged on user is one of the nine names. I want the code to loop thru the names and compare them to the logged on user and then enable or disable the combo box (as part of the form load, or very early in the code before the user gets to the combo box). What properties of the combo box do I use to get the text of the names that I originally added using Items.Add so that I can Loop through to compare to the name of the user? Some form of SelectedIndex? Some form of SelectedItem?
I think I should use something like
If cboName.XXX = GetUserName(gUserName) Then
cboName.Enabled = True
cboName.Enabled = False
In this example, gUserName would be tjones, his login name to the system. Timothy Jones would be the corresponding name in the combo box which was added earlier in another part of the code, and which would be returned by the GetUserName function.
But I cannot seem to get the XXX to come up with text name equal to the name (Timothy Jones) that I added with Items.Add. This has got to be simple, but I'm just missing it somewhere.
Can anyone help me here?
TIA for anything anyone can offer.
Dim UserName As String = GetUserName(gUserName)
For Each item As Object In cboName.Items
If item.ToString = UserName Then
cboName.SelectedItem = item