Breyta

Deila með


BindingList<T>.FindCore(PropertyDescriptor, Object) Method

Definition

Searches for the index of the item that has the specified property descriptor with the specified value, if searching is implemented in a derived class; otherwise, a 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

Parameters

prop
PropertyDescriptor

The PropertyDescriptor to search for.

key
Object

The value of prop to match.

Returns

The zero-based index of the item that matches the property descriptor and contains the specified value.

Exceptions

FindCore(PropertyDescriptor, Object) is not overridden in a derived class.

Examples

The following code example demonstrates how to use the FindCore member.

    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

Remarks

The BindingList<T> class does not provide a base implementation of searching, and so FindCore always throws a NotSupportedException by default. To enable searching, derive from BindingList<T> and perform the following tasks:

Applies to