Hello everybody, please assist me if how to validate if the item you want to add in the cart is already exists in listView items? for example I already add CH001 which is the productId of Chocolate strawberry, then I accidentally add again that product Id and what I want is that it should not be acccepted on my listview anymore because CH001 is already on my cart, I search many times about it, its been 1 week from now but I am not able to find how is it to be done, by the way I am adding items to my listview by textbox which auto-populates from my database, and below is my code for adding items in listview which is working properly but no validation.
private void cmdCart_Click(object sender, EventArgs e)
{
listView1.View = View.Details;
ListViewItem item2 = new ListViewItem(txtProductName.Text);
item2.Checked = true;
item2.SubItems.Add(txtProductPrice.Text);
item2.SubItems.Add(txtProductID.Text);
this.listView1.Items.AddRange(new ListViewItem[] { item2 });
}
I am using visual studio 2010 and I am barely new to c#, so sorry if I am noob, and so much thanks in advance. God Bless to all the helpful people, who are there to help such a noob like me :)
I've tried this one
if (!listView1.Items.ContainsKey(lvi.Name))
{
listView1.Items.Add(lvi);
}
else
{
MessageBox.Show("Duplicate Item!");
}
but no luck at all, probably you can explain me a little bit more. Thanks again.