Click to See Complete Forum and Search --> : Need a new ListBox
ABASYYX
August 4th, 2001, 10:02 AM
I need to add one particular quality to the ListBox to fit my needs. Each item added needs to have not just text but a variable along with it. This variable will be there to signify a catagory of the item. The catagory can't be shown, but is there so that if a user selects the item, the code will know what catagory to work with. The list of catagories will be a predetermined ammount, so I guess that the variable can refer to an Enumeration. I would like the line of code I write for the AddIem to look like this:
list1.AddItem ("This is the text.", Catagory1)
I assume that I need to use the ListBox in making a new ocx. How do I add this new bit of depth to the ListBox? Thanks for any help that anyone can give me.
deghost
August 5th, 2001, 09:14 AM
you can use 2 listboxes. 1 for data & one for variable. if you don't need it sorted, add them together (to different listboxes) and they will have the same index, if not... think of something, i'm sure there is a way to overcome this too.
----------
The @host is everywhere!
----------
John G Duffy
August 5th, 2001, 01:00 PM
Each Listbox item has a corresponding ITEMDATA method associated with it. It is a numerical value and can be used as a pointer to array element or a enumeration element etc.
Here is a very simple example:
option Explicit
Dim strMyarray(20)
private Sub Form_Load()
Dim X
strMyarray(0) = "This is Item 0"
strMyarray(1) = "This is Item 1"
strMyarray(2) = "This is Item 2"
strMyarray(3) = "This is Item 3"
strMyarray(4) = "This is Item 4"
strMyarray(5) = "This is Item 5"
strMyarray(6) = "This is Item 6"
strMyarray(7) = "This is Item 7"
strMyarray(8) = "This is Item 8"
strMyarray(9) = "This is Item 9"
strMyarray(10) = "This is Item 10"
for X = 1 to 10
List1.AddItem "Something in a list Number " & X
List1.ItemData(List1.NewIndex) = X
next X
End Sub
private Sub List1_Click()
Debug.print strMyarray(List1.ItemData(List1.ListIndex))
End Sub
John G
Bon La Lay
August 5th, 2001, 11:09 PM
You can use a listbox and a collection object.
As shown below:
Dim colList as New Collection
private sub adding()
List1.AddItem "item1"
colList.Add Category1, "key" & List1.NewIndex
end sub
//-----------------------------------------\\
Where there's a wire , there's a way
\\-----------------------------------------//
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.