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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Priniting a aray index value to a list box

Status
Not open for further replies.
Jun 30, 2003
196
GB
I have alist box and i want to add the item of an array to the list box i have tryed the following but it does not work.

lstShortcutItems.AddItem Shortcut1(1)

any ideas

 
myList.AddItem myAry(1)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
This should work! Are you getting any errors? Are you certain that shortcut1(1) is not empty? You might want to try msgbox shortcut1(1) to test it.
 
yeah i just run the debugger (f8) and i think if im following it logically the array may be empty at the time the list box is initialised. If this is not the problem ill get back to you guys.

thanks for da help till then
 
Ok i figured it out you were right

but next problem is how do i set the list item of choice i know i have to use the list boxs index

so if i wanted to set the contents of the arrays index to the first lst item how would i specify this

e.g set the following to the first list item
myList.AddItem myAry(1)
 
i dont understand how would that set the contents of the array to a specific item in the list box.
 
Sorry if I misuanderstood your question. That would set the item in index 0 as the default.

If you want to add a spesific item at the begining of the list add it first.

myList.AddItem myAry(1)

and then add the rest
 
Yes i know but i cant do it that way as i am allowing my user to choose what position in the list the item is placed. Do you know how i could place the item in the list at a certain position say the first position but without declaring it first like you suggested above
 
Maybe this will explain my problem clearer, i tryed this but the syntax is invalid so i need to find out how i can acheive this functionality

lstShortcutItems (1) = Shortcut1(1)

bassically set list item 1 to whatever shortcut1 item 1 is.

hope that helps
 
there is an optional parameter in ADDITEM where you can specify the index of the inserted item
Code:
myList.AddItem shortCut1(1),0
myList.AddItem shortCut1(3),1
myList.AddItem shortCut1(2),2
myList.AddItem shortCut1(0),3

myList.AddItem shortCut1(4),2 'will move the rest one position down and reindex
etc...

the only problem is that indexes have to be serial. So you can't add an item in index 3 if there isn't an index 2 and so on.
 
ok thats great im getting there now but i dont actually want it move them down.

so in your example above when you add shortcut1(4) to the list it takes on index 2 and moves the rest down so shortcut1(2) becomes index position 3 in the list box.

I want it it actually gets replaced and not moved down. Any advice what about if i removed it before adding the new item at index 2 would that work?

 
RemoveItem(2) will remove the third item

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
yes but when it has been removed an i execute the statement above will that be placed in the correct position still.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top