BBaron
asked on
help using data in combo boxes
Hello,
Whats the best way of storing a list of 2 columns in a combobox ?
Ie I have a list of forenames and a list of surnames. I only want to show the forenames but when I pick the forename I wish to use the surname in code.
any ideas?
cheers
Ben
Whats the best way of storing a list of 2 columns in a combobox ?
Ie I have a list of forenames and a list of surnames. I only want to show the forenames but when I pick the forename I wish to use the surname in code.
any ideas?
cheers
Ben
Take my OCX, it can handle mutiple columns and much more ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BY the way, meant to say that in method 1) you would set the visible property of the partner control to false so that it is not displayed to the user.
Put the surenames in collection like this:
Dim Mysurenames As Collection
Set Mysurenames = new Collection
Mysurenames.Add "Smith" , "John"
...
Then you can access the related surename with:
str_surename = Mysurenames("John")
Best regards
WoK ;o)
Dim Mysurenames As Collection
Set Mysurenames = new Collection
Mysurenames.Add "Smith" , "John"
...
Then you can access the related surename with:
str_surename = Mysurenames("John")
Best regards
WoK ;o)
VK, where can we try your OCX?
ComboBox has a ItemData property that is used for this purpose (Display one thing and pass another thing)
For eg. If you have the forname and surname in a array
vDataArray
with cmb1
For Idx = 0 To UBound(vDataArray, 2)
.AddItem vDataArray(1, Idx) 'forename
.ItemData(Idx) = vDataArray(0, Idx) 'surname
Next
end with
Hope it help
For eg. If you have the forname and surname in a array
vDataArray
with cmb1
For Idx = 0 To UBound(vDataArray, 2)
.AddItem vDataArray(1, Idx) 'forename
.ItemData(Idx) = vDataArray(0, Idx) 'surname
Next
end with
Hope it help
GoodJun, using the itemdata property when you already have an array is irrelevant because you can infer the element from the .ListIndex property. It would be handy if the itemdata property stored something other than an integer but it doesn't so in reality you are using an array method as I suggested earlier.
ASKER
Cheers Tim,
Im going with the collection suggestion
ps watch out for my next one!
Im going with the collection suggestion
ps watch out for my next one!