Delete Selected Item

Started by James (Aka: The Geek), Thu 13/07/2006 18:52:39

Previous topic - Next topic

James (Aka: The Geek)

I need my game to delete the item selected on the listbox when the user presses a button.

I have tried something simalar to this:

Ã,  Ã, int number = list.SelectedIndex;
Ã,  Ã,  Ã,  Ã,  list.RemoveItem(number);

When I run the game it says invalid index ???

Does anybody have any suggestions?
Ã,  Ã,  Ã, 
"I reject you reality and substitute my own"     -Adam Savage

"When 900 years old you reach look as good you will not"     -Yoda

"LLAP!"     -James

Ubel

Where exactly do you have this code placed in?

Are you sure you have an item selected when you are pressing the button?

James (Aka: The Geek)

Yes, I have already checked
The Error comes up when I press the button
"I reject you reality and substitute my own"     -Adam Savage

"When 900 years old you reach look as good you will not"     -Yoda

"LLAP!"     -James

Ubel

Hmm, tricky. The manual says:
QuoteNOTE: Calling this function causes other items in the list to get re-numbered, so make sure you don't keep around any references from ListBox.SelectedIndex and related functions while using this command.
So this might not work properly. But try this:

Try putting this on top of your global script:
Code: ags

int listboxnumber;


Then this into your ListboxSelectionChanged script:
Code: ags

listboxnumber=list.SelectedIndex;


Then this into on_key_press:
Code: ags

list.RemoveItem(listboxnumber);

monkey0506

It seems to me that you should still check...

Code: ags
if (list.SelectedIndex != -1) list.RemoveItem(list.SelectedIndex);


Should work fine.

SMF spam blocked by CleanTalk