ListView.SelectedListViewItemCollection.IndexOfKey(String) 方法

定义

返回具有指定键的项的第一个匹配项的索引。Returns the index of the first occurrence of the item with the specified key.

public:
 virtual int IndexOfKey(System::String ^ key);
public virtual int IndexOfKey (string key);
abstract member IndexOfKey : string -> int
override this.IndexOfKey : string -> int
Public Overridable Function IndexOfKey (key As String) As Integer

参数

key
String

要在集合中查找的项的名称。The name of the item to find in the collection.

返回

Int32

具有指定键的第一个项的索引(从零开始)。The zero-based index of the first item with the specified key.

注解

Name属性对应于中的的键 ListViewItem ListView.SelectedListViewItemCollectionThe Name property corresponds to the key for a ListViewItem in the ListView.SelectedListViewItemCollection.

密钥比较不区分大小写。The key comparison is not case-sensitive. 如果 key 参数为 null 或空字符串,则 IndexOfKey 返回-1。If the key parameter is null or an empty string, IndexOfKey returns -1.

如果 IndexOfKey 连续调用,最后返回的索引将首先检查键匹配项,如果没有匹配项,则从集合的开头开始搜索。If IndexOfKey is called successively, the last returned index will be checked for a key match first, and if there is no match, the search starts at the beginning of the collection.

适用于