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> 衍生並執行下列工作:

適用於