IBindingList.Find(PropertyDescriptor, Object) Méthode

Définition

Retourne l'index de la ligne possédant le PropertyDescriptor donné.

public:
 int Find(System::ComponentModel::PropertyDescriptor ^ property, System::Object ^ key);
public int Find (System.ComponentModel.PropertyDescriptor property, object key);
abstract member Find : System.ComponentModel.PropertyDescriptor * obj -> int
Public Function Find (property As PropertyDescriptor, key As Object) As Integer

Paramètres

property
PropertyDescriptor

PropertyDescriptor dans lequel effectuer la recherche.

key
Object

Valeur du paramètre property à rechercher.

Retours

Int32

Index de la ligne possédant le PropertyDescriptor donné.

Exceptions

Exemples

L’exemple de code suivant montre comment implémenter la Find méthode.

    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

Remarques

Cette méthode sélectionne la première ligne où la valeur du property paramètre est égale à la valeur du key paramètre.

Cette méthode est prise en charge si SupportsSearching elle est true, sinon cette méthode lève un NotSupportedException.

S’applique à