-
Now here's an easy yes/no question:
Can each item of a listbox (or combobox) have its own "Tag"? I'd like to display one thing but underlying it I'd like it to be something compeltely different. An example might be I'd like to show to the user a file name (e.g. "Autoexec.bat") but I'd like to store, associated with that item, the full path (e.g. "C:\Autoexec.bat").
Is that possible? How?
Thanks all,
Toot
-
You can do somthing like this:
Code:
Option Explicit
Private m_MyArray(5) As String ' Size should match the number of entrys in the ListBox
Private Sub Form_Load()
List1.AddItem "Autoexec.bat"
m_MyArray(0) = "C:\Autoexec.bat"
List1.AddItem "MyFile.txt"
m_MyArray(1) = "C:\Program Files\Microsoft Office\Office\Examples\Solver\MyFile.txt"
End Sub
Private Sub List1_Click()
MsgBox m_MyArray(List1.ListIndex)
End Sub
-
/// ??? \\\
yes..also can be done using MS Databound ListBox or ComboBox
set your listfield to your display item (field1)
set your boundtext to your hidden item (field2)
-
Yes, There is a property called ItemData to both listboxes and Combos, you can use it the same way as list
Code:
List1.AddItem "Autoexec.bat"
list1.itemdata(0) = "C:\Autoexec.bat"
List1.AddItem "MyFile.txt"
list1.itemdata(1) = "C:\Program Files\Microsoft Office\Office\Examples\Solver\MyFile.txt"
-
kedaman: Itemdata must be numeric.
-
I guess youre right Martin, i didn't think of that since i never used itemdata
anyway the listview control has a lot more features including tag's for each item
-
OK folks thanks for your help. Looks like I'll be using the listview control a bit more then :)
Toot
-
Totally off-topic
-
hmmm...Fox...i've notice you've increased a lot in your post count...is it because you helped a lot of people? Or because you've been posting a lot of useless messages like the one above?
-
Both I think :). I like helping people but also having fun.
However, I don't care about the post count... it primary tells you how much time people spend on this board ;)
Oh and most of these posts from me are in the chit chat forum where it doesn't count
-
Zej, What are you trying to accomplish? Don't yell on Fox, and definitely not on me or anybody else for posting freely
The only one caring about postcounts is you!