65.9K
CodeProject is changing. Read more.
Home

ListView Find Items Text

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.64/5 (9 votes)

Jun 8, 2007

CPOL
viewsIcon

83976

downloadIcon

2276

ListView Find Items string or integer etc: *text, or *text*, or text*

Title:       ListView Find Items Text
Author:      Suha Celik
Email:       suhacelik@pratek.com.tr
Member ID:   465222
Language:    C# 1.1 or 2.0 
Platform:    Windows, .NET 1.1 or .NET 2.0
Technology:  C#
Level:       Beginner
Description: ListView Find Items Text

ListViewFind

Introduction

ListView Find Items string or integer etc: *text, or *text*, or text*

Using the code

A brief desciption of how to use the article or code. The class names, the methods and properties, any tricks or tips.

        private int lastItm = 0;
.
.
.

private void button1_Click(object sender, EventArgs e)
        {
            int col = Convert.ToInt32(numericUpDown1.Value)-1;
            int colCount = col + 1;
            bool find = false;

            if (checkBox1.Checked)
            {
                colCount = listView1.Columns.Count;
                col = 0;
            }
            for (int colAll = col; colAll < colCount; colAll++)
            {
                for (int lst12 = lastItm; lst12 < listView1.Items.Count; lst12++)
                {
                    if (listView1.Items[lst12].SubItems[colAll].Text.IndexOf(textFind.Text) > -1 |
                        listView1.Items[lst12].SubItems[colAll].Text.ToUpper().IndexOf(textFind.Text.ToUpper()) > -1)
                    {
                        listView1.TopItem = listView1.Items[lst12];

                        if (checkBox2.Checked)
                        {
                            if (lastItm > 0) listView1.Items[lastItm - 1].BackColor = Color.Empty;
                            listView1.Items[lst12].BackColor = Color.Aqua;
                        }
                        lastItm = lst12 + 1;
                        find = true;
                        break;
                    }
                    
                }
                if (find)
                    break;
            }
        }

Enjoy...