FindItemWithText Method (String)

ListView.FindItemWithText Method (String)

Finds the first ListViewItem that begins with the specified text value.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public ListViewItem FindItemWithText(
	string text


Type: System.String
The text to search for.

Return Value

Type: System.Windows.Forms.ListViewItem
The first ListViewItem that begins with the specified text value.

The search is case-insensitive.

The text parameter can specify a substring of the desired matching text. In addition, this method will return the first item that starts with the specified text. For example, if a ListView contains two list items—the first item's text set to "angle bracket" and the second item's text set to "bracket"—a call to FindItemWithText passing brack as the parameter will return the item whose text is "bracket".

The FindItemWithText method returns null if the list is empty or there is no matching item.

The following code example demonstrates the FindItemWithText method. To run this example, paste the following code into a Windows Form and call the InitializeFindListView method from the form's constructor or Load event handler. Click the button to see the results of the method call.

		// Declare the ListView and Button for the example.
        ListView findListView = new ListView();
        Button findButton = new Button();

        private void InitializeFindListView()
	    // Set up the location and event handling for the button.
            findButton.Click += new EventHandler(findButton_Click);
            findButton.Location = new Point(10, 10);
	    // Set up the location of the ListView and add some items.
	    findListView.Location = new Point(10, 30);
            findListView.Items.Add(new ListViewItem("angle bracket"));
            findListView.Items.Add(new ListViewItem("bracket holder"));
            findListView.Items.Add(new ListViewItem("bracket"));

            // Add the button and ListView to the form.

		void findButton_Click(object sender, EventArgs e)
	            // Call FindItemWithText, sending output to MessageBox.
		    ListViewItem item1 = findListView.FindItemWithText("brack");
			 if (item1 != null)
				 MessageBox.Show("Calling FindItemWithText passing 'brack': " 
                     + item1.ToString());
				 MessageBox.Show("Calling FindItemWithText passing 'brack': null");

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft