This How To was written in response to the following question in the C# Corner Forums about ListViews:
The user states:
Question: "I have code which I used to check duplication in a ListView, but it doesn't seem to be working. Here is my situation. I have three columns in a ListView and I want to check to make sure that I don't duplicate a field when I add an item to the ListView. How do I do that?"
I tried this code, but it doesn't seem to work:
if (listView1.Items.Contains(lvi) == false) { //Add the item to the ListView Control listView1.Items.Add(lvi); } else { //Warn user of duplicate entry... MessageBox.Show("Duplicate Item!"); } |