1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to remove specific item from listView

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

  1. shah123

    shah123 New Member

    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

    while (scheduleListView.SelectedItems.Count > 0)
    {
    scheduleListView.Items.Remove(scheduleListView.SelectedItems[0]);
    }

    It worked . Thanks anyway
     

Share This Page