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.

C#
protected virtual int FindCore(System.ComponentModel.PropertyDescriptor prop, object key);

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.

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

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

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1