Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ListView Find Items Text

0.00/5 (No votes)
8 Jun 2007 1  
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...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here