467,922 Members | 1,289 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,922 developers. It's quick & easy.

remove from listBox

How to remove a selected item from listBox?

Hrcko
Nov 17 '05 #1
  • viewed: 2319
Share:
3 Replies
Hrcko wrote:
How to remove a selected item from listBox?

[...snip...]

foreach (ListViewItem item in this.myListBox.Items)

{

item.Selected = false;

};
Nov 17 '05 #2
> How to remove a selected item from listBox?
[...snip...]

O.k., that was how to deselect all items. I should read the postings
properly before responding...

To remove the selected item, use

ListViewItem itemToRemove;
foreach (ListViewItem item in this.myListBox.Items)

{

if (item.Selected == true)

{

itemToRemove = item;

break;

};

};

this.myListBox.Items.Remove(itemToRemove);

If you happen to already know the selected ListViewItem, leave out
everything except the last line. Putting the foreach loop into a method of
it's own might be a good idea...
Nov 17 '05 #3
Hi,

Get the selected index from the dropdownlist.selectedIndex property and
use dropdownlist.removeat(index) method.

HTH,
Regards,
Angrez

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Supra | last post: by
4 posts views Thread by Bilo | last post: by
4 posts views Thread by mostafa atalla | last post: by
1 post views Thread by deepak | last post: by
3 posts views Thread by Bill Nguyen | last post: by
11 posts views Thread by Andrus | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.