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

Definizione

Ricerca l'indice dell'elemento che ha il descrittore di proprietà specificato con il valore specificato, se la ricerca è implementata in una classe derivata; in caso contrario un oggetto 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

Parametri

prop
PropertyDescriptor

Oggetto PropertyDescriptor da cercare.

key
Object

Valore di prop da cercare.

Restituisce

Indice in base zero dell'elemento che corrisponde al descrittore di proprietà e che contiene il valore specificato.

Eccezioni

Il metodo FindCore(PropertyDescriptor, Object) non viene sottoposto a override in una classe derivata.

Esempio

Nell'esempio di codice seguente viene illustrato come usare il FindCore membro .

    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

Commenti

La BindingList<T> classe non fornisce un'implementazione di base della ricerca e quindi FindCore genera sempre un'eccezione per NotSupportedException impostazione predefinita. Per abilitare la ricerca, derivare da BindingList<T> ed eseguire le attività seguenti:

Si applica a