ListView.FindItemWithText 方法

定义

查找以给定文本值开头的第一个 ListViewItem 值。

重载

名称 说明
FindItemWithText(String)

查找以指定文本值开头的第一个 ListViewItem 值。

FindItemWithText(String, Boolean, Int32)

查找以指定文本值开头的第一个 ListViewItemListViewItem.ListViewSubItem(如果指示)。 搜索从指定的索引开始。

FindItemWithText(String, Boolean, Int32, Boolean)

查找以指定文本值开头的第一个 ListViewItemListViewItem.ListViewSubItem(如果指示)。 搜索从指定的索引开始。

FindItemWithText(String)

Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs

查找以指定文本值开头的第一个 ListViewItem 值。

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

参数

text
String

要搜索的文本。

返回

第一个 ListViewItem 以指定文本值开头。

示例

下面的代码示例演示了该方法 FindItemWithText 。 若要运行此示例,请将以下代码粘贴到 Windows 窗体中,并从窗体的构造函数或InitializeFindListView事件处理程序调用Load该方法。 单击该按钮可查看方法调用的结果。

// 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

注解

搜索不区分大小写。

text 参数可以指定所需匹配文本的子字符串。 此外,此方法将返回以指定文本开头的第一个项目。 例如,如果一个列表项包含两个 ListView 列表项-第一项的文本设置为“尖括号”,而第二个项目的文本设置为“括号”,则调用 FindItemWithText 作为参数传递 brack 将返回其文本为“bracket”的项。

如果列表为空或没有匹配项,则 FindItemWithText 该方法返回 null

适用于

FindItemWithText(String, Boolean, Int32)

Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs

查找以指定文本值开头的第一个 ListViewItemListViewItem.ListViewSubItem(如果指示)。 搜索从指定的索引开始。

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

参数

text
String

要搜索的文本。

includeSubItemsInSearch
Boolean

true 在搜索中包含子项;否则,为 false.

startIndex
Int32

开始搜索的项的索引。

返回

第一个 ListViewItem 以指定文本值开头。

例外

小于 0 或大于 /a0> 中的项数。

注解

搜索不区分大小写。

text 参数可以指定所需匹配文本的子字符串。 此外,此方法将返回以指定文本开头的第一个项目。 例如,如果包含两个 ListView 列表项-第一个项目的文本设置为“尖括号”,而第二项的文本设置为“括号”,则调用 FindItemWithText 传递“brack”作为参数将返回其文本为“bracket”的项目。

如果列表为空或没有匹配项,则 FindItemWithText 该方法返回 null

适用于

FindItemWithText(String, Boolean, Int32, Boolean)

Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs
Source:
ListView.cs

查找以指定文本值开头的第一个 ListViewItemListViewItem.ListViewSubItem(如果指示)。 搜索从指定的索引开始。

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

参数

text
String

要搜索的文本。

includeSubItemsInSearch
Boolean

true 在搜索中包含子项;否则,为 false.

startIndex
Int32

开始搜索的项的索引。

isPrefixSearch
Boolean

true 允许部分匹配;否则,为 false.

返回

第一个 ListViewItem 以指定文本值开头。

例外

startIndex 小于 0 或大于项目中 ListView的项数。

注解

如果列表为空或没有匹配项,则 FindItemWithText 该方法返回 null

搜索不区分大小写。

text 参数可以指定所需匹配文本的子字符串。 此方法将返回以指定文本开头的第一项,除非 false 传入指定文本 isPrefixSearch。 例如,如果包含两个 ListView 列表项-第一个项目的文本设置为“尖括号”,而第二个项目的文本设置为“括号”,则调用 FindItemWithText 传递“brack”作为搜索文本将返回其文本为“括号”的项目。 如果 isPrefixSearch 设置为 false,此调用将返回 null

适用于