remove from listBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hrcko

    #1

    remove from listBox

    How to remove a selected item from listBox?

    Hrcko
  • Michael Voss

    #2
    Re: remove from listBox

    Hrcko wrote:
    [color=blue]
    > How to remove a selected item from listBox?[/color]
    [...snip...]

    foreach (ListViewItem item in this.myListBox. Items)

    {

    item.Selected = false;

    };


    Comment

    • Michael Voss

      #3
      Re: remove from listBox

      > 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(it emToRemove);

      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...


      Comment

      • Angrez Singh

        #4
        Re: remove from listBox

        Hi,

        Get the selected index from the dropdownlist.se lectedIndex property and
        use dropdownlist.re moveat(index) method.

        HTH,
        Regards,
        Angrez

        Comment

        Working...