-2

I have a textBox where you can enter a name then you can click on a Button to delete that item with that name in a listview.

private void btnDelete_Click(object sender, EventArgs e)
{
  foreach (ListViewItem Searchstr in listView1.Name)
   {
      listView1.Items.Remove(Searchstr);
   }
}

Any idea on how to make this work?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
  • 1
    Possible duplicate of [C# removing items from listbox](http://stackoverflow.com/questions/2096489/c-sharp-removing-items-from-listbox) – MethodMan Aug 19 '16 at 14:03
  • A simple google search of your Title yields many results.. please show more effort on your part next time .. respectfully speaking .. – MethodMan Aug 19 '16 at 14:04
  • There should be no `ListViewItem`s in `listView1.Name`. I mean it. Not even a single one. – Sinatr Aug 19 '16 at 14:11

1 Answers1

0
void deleteItemFromListBox(string stringToDelete, ListView listBoxToDeleteItem)
{
for (int i = 0; i < listBoxToDeleteItem.Items.Count; i++)
{
if(stringToDelete==listBoxToDeleteItem.Items[i].Text)
{
  listBoxToDeleteItem.Items[i].Remove();
}
}
}

Function takes string and listview than deletes listview element that contains the string.

huse.ckr
  • 530
  • 12
  • 39