Link to home
Start Free TrialLog in
Avatar of BBaron
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
Avatar of VK
VK
Flag of Germany image

Take my OCX, it can handle mutiple columns and much more ...
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of WolfgangKoenig
WolfgangKoenig

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)

Avatar of Éric Moreau
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
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.
Avatar of BBaron

ASKER

Cheers Tim,
  Im going with the collection suggestion
 ps watch out for my next one!