Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Key propery for Combo box -Help required with an alternative

Status
Not open for further replies.

whool

Programmer
Jan 31, 2002
31
AU
I want to display values in combo box but hide key data for each row. (With Listview or treeview you can just use the Key property but Combobox doesn't have this.) When the user hits a command button on the same form I want the Key value corresponding to the selected value in the combo to be passed as a parameter to a Store Proc on SQLSver.

I believe it should be possible to use a Datacombo control and bind it to the data but I am loath to use either of these as their properties cannot be set at run-time. (Correct me if I am wrong).

I'm am not trying to do anything out of the ordinary here; surly there is a simple solution to this problem...any clues would be much appreciated.

Thnaks in advance,

Yael





 
You can store the keys in the ItemData property of the combo.
combo1.Itemdata(i) = ID

i being the listindex value of the current record in the combo
ID being a long value such as Autonumber primary key in an Access table

When adding records use this -

cb.AddItem RTrim(rs.Fields.Item(strItem).Value)
cb.ItemData(cb.NewIndex) = rs.Fields.Item(ID).Value Rob
rob@crombie.com
 
Thanks Rob but this solution only works for integers. The keys I need to store are GUIDs (38 character strings)



 
Store the GUIDS in an array that is parallel to the ComnboBox entries or store them on the right side of the Combo Box entry, wider than than the Width of the control. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks JohnYingLing,

The paralell array sounds a good solution...quite obvious really.

Cheers,

Yael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top