How to remove specific item from listView

Discussion in 'C#' started by shah123, May 4, 2007.

  1. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to remove item from ListView but when i click on remove it doesnt remove the last item or in the middle but when i select the first item it removes.

    How is it possible to remove any selected item in the list?

    Code:
    private void removeBtn_Click(object sender, EventArgs e)
            {
                
                for (int i = scheduleListView.SelectedItems.Count - 1; i >= 0; i--)
                {
                    if (scheduleListView.Items[i].Selected)
                    {
                        scheduleListView.Items.Remove(scheduleListView.Items[i]);
                    }
                }
    
            }
    
    
    Thanks
     
  2. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    while (scheduleListView.SelectedItems.Count > 0)
    {
    scheduleListView.Items.Remove(scheduleListView.SelectedItems[0]);
    }

    It worked . Thanks anyway
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice