vendredi 27 février 2015

How to avoid duplicate items on a listview

I have a string array of 3 elements and i have to display it on a listView having three columns,but,before each add have to avoid duplicate addition of elements to listview.


Following is the code where i add elements to the list.



arr[0] = ip;
arr[1] = hostname;
arr[2] = macaddres;
// Logic for Ping Reply Success
ListViewItem item;
if (this.InvokeRequired)
{

this.Invoke(new Action(() =>
{

item = new ListViewItem(arr);

//**needed trick here to check for duplicate addition**
lstLocal.Items.Add(item);
int count = lstLocal.Items.Count;
toolStripStatusLabel4.Text = string.Format(count.ToString() + " Item(s)");
}
}));
}


The Containskey() and Contains()didn't work for me.


Aucun commentaire:

Enregistrer un commentaire