IBindingList.Find(PropertyDescriptor, Object) Method

Definition

Returns the index of the row that has the given PropertyDescriptor.

C#
public int Find(System.ComponentModel.PropertyDescriptor property, object key);

Parameters

property
PropertyDescriptor

The PropertyDescriptor to search on.

key
Object

The value of the property parameter to search for.

Returns

The index of the row that has the given PropertyDescriptor.

Exceptions

Examples

The following code example demonstrates how to implement the Find method.

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

This method will select the first row where the value of the property parameter equals the value of the key parameter.

This method is supported if SupportsSearching is true, otherwise this method throws a NotSupportedException.

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, 10
.NET Framework 1.1, 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