ListView.FindItemWithText Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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
Available since 2.0
Return to top