Share via


IBindingList.Find 方法

返回具有给定 PropertyDescriptor 的行的索引。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Function Find ( _
    property As PropertyDescriptor, _
    key As Object _
) As Integer
用法
Dim instance As IBindingList
Dim property As PropertyDescriptor
Dim key As Object
Dim returnValue As Integer

returnValue = instance.Find(property, key)
int Find (
    PropertyDescriptor property,
    Object key
)
int Find (
    PropertyDescriptor^ property, 
    Object^ key
)
int Find (
    PropertyDescriptor property, 
    Object key
)
function Find (
    property : PropertyDescriptor, 
    key : Object
) : int

参数

  • key
    要搜索的 property 参数的值。

返回值

具有给定 PropertyDescriptor 的行的索引。

异常

异常类型 条件

NotSupportedException

SupportsSearchingfalse

备注

该方法将选择 property 参数的值与 key 参数的值相等的第一行。

如果 SupportsSearchingtrue,则支持该方法,否则该方法引发 NotSupportedException

示例

下面的代码示例演示如何实现 Find 方法。

Public Class MyFontList
    Inherits BindingList(Of Font)

    Protected Overrides ReadOnly Property SupportsSearchingCore() As Boolean
        Get
            Return True
        End Get
    End Property
    
    Protected Overrides Function FindCore(ByVal prop As PropertyDescriptor, _
        ByVal key As Object) As Integer
        ' Ignore the prop value and search by family name.
        Dim i As Integer
        While i < Count
            If Items(i).FontFamily.Name.ToLower() = CStr(key).ToLower() Then
                Return i
            End If
            i += 1
        End While

        Return -1
    End Function
End Class
    public class MyFontList : BindingList<Font>
    {

        protected override bool SupportsSearchingCore
        {
            get { return true; }
        }
        protected override int FindCore(PropertyDescriptor prop, object key)
        {
            // Ignore the prop value and search by family name.
            for (int i = 0; i < Count; ++i)
            {
                if (Items[i].FontFamily.Name.ToLower() == ((string)key).ToLower())
                    return i;

            }
            return -1;
        }


    }
  
}

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

IBindingList 接口
IBindingList 成员
System.ComponentModel 命名空间