|
-
Jun 28th, 2000, 04:13 AM
#1
Thread Starter
Hyperactive Member
Combo1.ItemData problem
I have a text file with FirstNames and LastNames:
"names.txt"
Tom, Johns
Joe, Jordan
Ted, Brown
...etc.
There's a ComboBox & a Label on the form.
I want to read in FirstNames (first column) into a ComboBox, and somehow reference to them LastNames (second column). So when user selects a first name from ComboBox, the corresponding Last name will show on a Label beside it.
example (see names above):
user clicks on Joe in the ComboBox, and Jordan appears in on the Label.
---------------------------------------------------------
MSDN suggests using .ItemData property but I couldn't get it to work with my file access stuff.
MSDN's example of .ItemData
Private Sub Form_Load ()
' Fill List1 and ItemData array with
' corresponding items in sorted order.
List1.AddItem "Judy Phelps"
List1.ItemData(List1.NewIndex) = 42310
List1.AddItem "Chien Lieu"
List1.ItemData(List1.NewIndex) = 52855
List1.AddItem "Mauro Sorrento"
List1.ItemData(List1.NewIndex) = 64932
List1.AddItem "Cynthia Bennet"
List1.ItemData(List1.NewIndex) = 39227
End Sub
Private Sub List1_Click ()
' Append the employee number and the employee name.
Msg = List1.ItemData(List1.ListIndex) & " "
Msg = Msg & List1.List(List1.ListIndex)
Label1.Caption = Msg
End Sub
---------------------------------------------------------
Any suggestions?
Thanx again
-
Jun 28th, 2000, 04:36 AM
#2
Hyperactive Member
here is a quick fix.
have a hidden listbox which contains only the last names. when a user clicks on one of the first names in the combo box, reference the hidden listbox with the same index from the combo box, and you have your last name, which you can place into the label.
Is this what you needed to do?
-
Jun 28th, 2000, 05:06 AM
#3
Shickadance is right. Only numeric (Long) values can be stored in the ItemData property array of a combo or listbox.
"It's cold gin time again ..."
Check out my website here.
-
Jun 28th, 2000, 08:09 AM
#4
Thread Starter
Hyperactive Member
Thanks guys, but I don't think this is going to work because I need to add the names to the text file as I go along. Also I wouldn't be able to sort the combobox without losing ties between FirstNames & LastNames.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|