Redigeeri

Jagamisviis:


ListView.FindItemWithText Method

Definition

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

Overloads

FindItemWithText(String)

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

FindItemWithText(String, Boolean, Int32)

Finds the first ListViewItem or ListViewItem.ListViewSubItem, if indicated, that begins with the specified text value. The search starts at the specified index.

FindItemWithText(String, Boolean, Int32, Boolean)

Finds the first ListViewItem or ListViewItem.ListViewSubItem, if indicated, that begins with the specified text value. The search starts at the specified index.

FindItemWithText(String)

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

public:
 System::Windows::Forms::ListViewItem ^ FindItemWithText(System::String ^ text);
public System.Windows.Forms.ListViewItem FindItemWithText (string text);
public System.Windows.Forms.ListViewItem? FindItemWithText (string text);
member this.FindItemWithText : string -> System.Windows.Forms.ListViewItem
Public Function FindItemWithText (text As String) As ListViewItem

Parameters

text
String

The text to search for.

Returns

The first ListViewItem that begins with the specified text value.

Examples

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.
    this.Controls.Add(findButton);
    this.Controls.Add(findListView);
}

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());
     else
         MessageBox.Show("Calling FindItemWithText passing 'brack': null");
 }
' Declare the ListView and Button for the example.
Private findListView As New ListView()
Private WithEvents findButton As New Button()


Private Sub InitializeFindListView()

    ' Set up the location and event handling for the button.
    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.
    Me.Controls.Add(findButton)
    Me.Controls.Add(findListView)

End Sub

Private Sub findButton_Click(ByVal sender As Object, ByVal e As EventArgs) _
    Handles findButton.Click

    ' Call FindItemWithText, sending output to MessageBox.
    Dim item1 As ListViewItem = findListView.FindItemWithText("brack")
    If (item1 IsNot Nothing) Then
        MessageBox.Show("Calling FindItemWithText passing 'brack': " _
            & item1.ToString())
    Else
        MessageBox.Show("Calling FindItemWithText passing 'brack': null")
    End If

End Sub

Remarks

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.

Applies to

FindItemWithText(String, Boolean, Int32)

Finds the first ListViewItem or ListViewItem.ListViewSubItem, if indicated, that begins with the specified text value. The search starts at the specified index.

public:
 System::Windows::Forms::ListViewItem ^ FindItemWithText(System::String ^ text, bool includeSubItemsInSearch, int startIndex);
public System.Windows.Forms.ListViewItem FindItemWithText (string text, bool includeSubItemsInSearch, int startIndex);
public System.Windows.Forms.ListViewItem? FindItemWithText (string text, bool includeSubItemsInSearch, int startIndex);
member this.FindItemWithText : string * bool * int -> System.Windows.Forms.ListViewItem
Public Function FindItemWithText (text As String, includeSubItemsInSearch As Boolean, startIndex As Integer) As ListViewItem

Parameters

text
String

The text to search for.

includeSubItemsInSearch
Boolean

true to include subitems in the search; otherwise, false.

startIndex
Int32

The index of the item at which to start the search.

Returns

The first ListViewItem that begins with the specified text value.

Exceptions

startIndex is less 0 or more than the number items in the ListView.

Remarks

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.

Applies to

FindItemWithText(String, Boolean, Int32, Boolean)

Finds the first ListViewItem or ListViewItem.ListViewSubItem, if indicated, that begins with the specified text value. The search starts at the specified index.

public:
 System::Windows::Forms::ListViewItem ^ FindItemWithText(System::String ^ text, bool includeSubItemsInSearch, int startIndex, bool isPrefixSearch);
public System.Windows.Forms.ListViewItem FindItemWithText (string text, bool includeSubItemsInSearch, int startIndex, bool isPrefixSearch);
public System.Windows.Forms.ListViewItem? FindItemWithText (string text, bool includeSubItemsInSearch, int startIndex, bool isPrefixSearch);
member this.FindItemWithText : string * bool * int * bool -> System.Windows.Forms.ListViewItem
Public Function FindItemWithText (text As String, includeSubItemsInSearch As Boolean, startIndex As Integer, isPrefixSearch As Boolean) As ListViewItem

Parameters

text
String

The text to search for.

includeSubItemsInSearch
Boolean

true to include subitems in the search; otherwise, false.

startIndex
Int32

The index of the item at which to start the search.

isPrefixSearch
Boolean

true to allow partial matches; otherwise, false.

Returns

The first ListViewItem that begins with the specified text value.

Exceptions

startIndex is less than 0 or more than the number of items in the ListView.

Remarks

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

The search is case-insensitive.

The text parameter can specify a substring of the desired matching text. This method will return the first item that starts with the specified text, unless false is passed in for isPrefixSearch. 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 search text will return the item whose text is "bracket". If isPrefixSearch is set to false, this call will return null.

Applies to