Partilhar via


BindingList<T>.FindCore(PropertyDescriptor, Object) Método

Definição

Pesquisa o índice do item que tem o descritor de propriedade especificado com o valor especificado, se a pesquisa for implementada em uma classe derivada; caso contrário, um 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

Parâmetros

prop
PropertyDescriptor

A PropertyDescriptor pesquisa a ser pesquisada.

key
Object

O valor de prop correspondência.

Retornos

O índice baseado em zero do item que corresponde ao descritor de propriedade e contém o valor especificado.

Exceções

FindCore(PropertyDescriptor, Object) não é substituído em uma classe derivada.

Exemplos

O exemplo de código a seguir demonstra como usar o FindCore membro.

public class MyFontList : BindingList<Font>
{
    protected override bool SupportsSearchingCore => 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.Equals((string)key, StringComparison.CurrentCultureIgnoreCase))
            {
                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

Comentários

A BindingList<T> classe não fornece uma implementação base de pesquisa e, portanto FindCore , sempre lança uma NotSupportedException por padrão. Para habilitar a pesquisa, derive BindingList<T> e execute as seguintes tarefas:

Aplica-se a