Listbox associated values

BlitzPlus Forums/BlitzPlus Programming/Listbox associated values

Pudsy(Posted 2003) [#1]
Just wondered if there is any way to associate a value with each item in a listbox. This could be a pointer to a type, or an image or sound or whatever. Or maybe a way to embed the value in the gadget item text so that it doesn't actually appear in the listbox, but can be retrieved with GadgetItemText(...)

Thanks.


Pudsy(Posted 2003) [#2]
Ha! Got it! :)

AddGadgetItem listbox, "DisplayText"+Chr$(0)+"AssociatedValue"

Only the 'DisplayText' bit shows in the list.

The entire string can be picked up later using GadgetItemText(...) and after a quick search for the Chr$(0) with InStr() you can get the associated value back.

Hope that sneaky little trick is as useful to someone else as it will be to me :)

Edit: Of course it only works for values/strings (not objects like types or sounds etc.) but it's better than nothing!