Showing posts with label ListView. Show all posts
Showing posts with label ListView. Show all posts

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 ); }

Friday, May 16, 2008

How to change background color of Listview in C#

Hello guyz. I have simple code here to change the background color of Listview and it's cells during runtime.

Step 1:
Create first a Listview.

Step 2:
Put this code at your form_load event.

listView1.Items.Add("Hello World");
listView1.Items[0].SubItems[0].BackColor = Color.Blue;