Will combobox.ItemData accept a string

When I try to add a string to the ItemData array I get a type mismatch error. It accepts integers OK.

What is wrong.

Who is Participating?
rkot2000Connect With a Mentor Commented:
if you want to store a string, you need to create an array of strings and store item index in the itemdata propery.

Éric MoreauSenior .Net ConsultantCommented:
ItemData is a collection of LONG. You can't set it to strings.
yup.... unfortunately they're both right... it can be a pain..

I usually use the itemdata to store a bookmark from a recordset when the combo is populated, then if I wish to retrieve the record relevant to whatever is selected in the combo, I can simply use

Recordset.Bookmark = combo.itemdata(combo.listindex)
and pull whatever data direct from the recordset
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

ps...my method is a little flawed before anyone points it out - as the bookmark property actually returns a double within a variant.
However with current versions of ADO, the value of the double is always integer, so I can use the itemdata property
<fingers crossed that this doesn't change in later versions...>
to nutwiss :
if it's a disconnected recordset you can store AbsolutePos.

p.s. you should not sort or filter your recodset after ...  
nutwiss,  no need to worry, as THERE WILL BE NO LATER VERSIONS of VB... VB has been replaced by VB.NET, which allows the ItemData property to hold a OBJECT reference, so you can use almost ANYTHING you desire.  

Arthur Wood
Yes, Arthur, i know - I meant any later versions of ADO :)
and rkot - I usually do filter or sort, that's why I use the bookmark...

Merlin, hope these suggestions help.
merlin007Author Commented:
Thanks everyone

This was a great help

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.