# Deleting the selected item in a listbox

**URL:** <https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417>\
**Category:** Uncategorized\
**Created:** [October 7, 2002, 3:03am UTC](https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417 "2002-10-07T03:03:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![babbaladoobala](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@babbaladoobala](https://forum.kirupa.com/u/babbaladoobala)\
**Post date:** [October 7, 2002, 3:03am UTC](https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417/1 "2002-10-07T03:03:08Z")

</div>

list.removeItemAt () \<-- how can I set this parameter so that it only deletes the selected item? I understand that I can place an integer (say 4) there, but then it only deletes whatever is in place 4. What if the 3rd place were highlighted?

Is there a way that I can modify this script so that the parameter slot will understand that it is supposed to delete place 3 (or 2 or 12)?

I really appreciate you reading this whole thing - thank you -

Sam

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 7, 2002, 5:22am UTC](https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417/2 "2002-10-07T05:22:20Z")

</div>

This is not difficult at all… just add the following code to your change handler (the name of my change handler is OnChange)

```auto

onChange=function(flistbox){
	flistbox.removeItemAt(flistbox.getselectedindex);
}

```

Hope that answers your question.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 7, 2002, 6:04am UTC](https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417/3 "2002-10-07T06:04:52Z")

</div>

this worked (but only when we clicked the button, then selected the item):

onChange=function(flistbox){  
flistbox.removeItemAt(flistbox.getselectedindex);  
}

unfortunately, what we are trying to do is select the item, and then click the remove button -

I appreciate your time on this :-\ if you have any advice, I would be most grateful -

Thank you -

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 7, 2002, 6:52am UTC](https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417/4 "2002-10-07T06:52:18Z")

</div>

no problem… forget the OnChange event.

I named my listbox instance “mybox”

I created a button and attached the following code to the button:

```auto

on(release){
	
mybox.removeitemat(mybox.getselectedindex());
}

```

there you go…!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 7, 2002, 7:06pm UTC](https://forum.kirupa.com/t/deleting-the-selected-item-in-a-listbox/6417/5 "2002-10-07T19:06:23Z")

</div>

that really does work!

:rambo:
