Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to remove specific Item from ListView
 

How to remove specific Item from ListView

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?
Thanks- Please Help

Below is the code snippet
Code Snippet

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]); } } }

shah123  Friday, May 04, 2007 9:42 AM

I feel a more elegant solution would be

Code Snippet

foreach (ListViewItem item in listView1.SelectedItems)

{

listView1.Items.Remove(item);

}

Regards

andypai  Friday, May 04, 2007 10:48 AM
while (scheduleListView.SelectedItems.Count > 0)
{
scheduleListView.Items.Remove(scheduleListView.SelectedItems[0]);
}

this is the sol. Thanks anyway
shah123  Friday, May 04, 2007 10:07 AM

I feel a more elegant solution would be

Code Snippet

foreach (ListViewItem item in listView1.SelectedItems)

{

listView1.Items.Remove(item);

}

Regards

andypai  Friday, May 04, 2007 10:48 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView checkbox and Indeterminate
• add new record in the binding datasource using BindingManagerBase.AddNew() method
• Creating XML from DataSet, I need null values to appear in the XML
• DataGridView - SLOW formatting (possible solution?)
• Simulate the escape key in the DataGridView Text Box Cell
• parameterizing data objects & binding
• no selected cells in the datagridview
• Add EventHandler, SelectedItemChanged, Combox control
• Why more than one datagridview cells are highlighted
• OleDbConnection