BindingList<T>.FindCore(PropertyDescriptor, Object) 方法

定义

如果在派生类中实现了搜索,则用指定值搜索具有指定属性说明符的项的索引;否则将引发 NotSupportedException

protected:
 virtual int FindCore(System::ComponentModel::PropertyDescriptor ^ prop, System::Object ^ key);
protected virtual int FindCore (System.ComponentModel.PropertyDescriptor prop, object key);
abstract member FindCore : System.ComponentModel.PropertyDescriptor * obj -> int
override this.FindCore : System.ComponentModel.PropertyDescriptor * obj -> int
Protected Overridable Function FindCore (prop As PropertyDescriptor, key As Object) As Integer

参数

prop
PropertyDescriptor

要搜索的 PropertyDescriptor

key
Object

要匹配的 prop 值。

返回

与属性说明符匹配并包含指定值的项的从零开始的索引。

例外

示例

下面的代码示例演示如何使用 FindCore 成员。

    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;
        }
    }
}
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

注解

BindingList<T> 不提供搜索的基本实现,因此 FindCore 默认情况下始终引发 NotSupportedException 。 若要启用搜索,请从 BindingList<T> 派生并执行以下任务:

适用于