Click to See Complete Forum and Search --> : List Box AddItem Method


Mongoose
January 25th, 2000, 11:53 AM
hopefully this will be a quick (easy question)

ok my list box is sorted so when i add an item via AddItem i want to know what index it added it to because i need to set the ItemData for that new index i just added

i thought i coulde do the following..

dim newIdx as integer
newIdx = list.AddItem "Text"

list.ItemData( newIdx ) = ID

any suggestions as to how i can do something like the code above?

thankx,

fotisgpap
January 25th, 2000, 12:39 PM
You can get the index oof the most recently added item in a listbox by getting the property NewIndex of the list control, for example:

dim myIndx as long
List1.Clear
List1.AddItem "ABC"
List1.AddItem "ZXY"
List1.AddItem "EFG"
myIndx = list1.NewIndex
' myIndx contains the index number of EFG wich is 2