Prevent double entries in ListView using C#?

前端 未结 6 1843
日久生厌
日久生厌 2021-01-16 09:59

How can we access the items added to a ListView?

The thing I have to do is: add an item to the list view. I want to check if the item to add to the listview is alrea

6条回答
  •  野的像风
    2021-01-16 10:15

    You could do something like this:

     ListViewItem itemToAdd;
     bool exists = false;
     foreach (ListViewItem item in yourListView.Items) 
     {
        if(item == itemToAdd)
            exists=true;
     }
    
     if(!exists)
         yourListView.Items.Add(itemToAdd);
    

提交回复
热议问题