Click here to Skip to main content
15,868,340 members
Articles / Programming Languages / C#
Article

ListView Find Items Text

Rate me:
Please Sign up or sign in to vote.
2.64/5 (9 votes)
8 Jun 2007CPOL 83.3K   2.3K   17   4
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer PROVERI Tech
Turkey Turkey
Dos , What? Smile | :) (1987 - Goldstar PC)
hmm Dos beautiful,
!!! basic , hello , what?
and next Life Cycle with BASIC (1989)
next VB6
next ASP
next soldier Smile | :)
now full mixed Smile | :)
MSVS 2003 - 2005
Borland c++
ASP
Java
vs....

Comments and Discussions

 
GeneralCode Fragment, not an article Pin
ednrgc8-Jun-07 6:35
ednrgc8-Jun-07 6:35 
AnswerRe: Code Fragment, not an article Pin
Suha8-Jun-07 11:31
Suha8-Jun-07 11:31 
QuestionWAT IS THIS??? Pin
pablleaf8-Jun-07 6:34
pablleaf8-Jun-07 6:34 
AnswerRe: WAT IS THIS??? Pin
Suha8-Jun-07 11:33
Suha8-Jun-07 11:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.