Thursday, August 28, 2008

Check Item in listview if exist

Hello guys.

This sample code will show on how to check if the item in the listview is already existing.

// create a bool
bool found = false;

foreach (ListViewItem LVI1 in listView1.Items)
{
if (LVI1.Text == textBox1.Text)
{ found = true; }
}

if (!found)
{
ListViewItem LVI = new ListViewItem(textBox1.Text, 0);
LVI.SubItems.Add(textBox2.Text);
LVI.SubItems.Add(textBox3.Text);
listView1.Items.Add(LVI);
}
else
{ MessageBox.Show("Found " + textBox1.Text ); }

No comments: