Language

IBindingList.Find(PropertyDescriptor, Object) メソッド

定義

指定した PropertyDescriptorを持つ行のインデックスを返します。

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

パラメーター

property
PropertyDescriptor

検索する PropertyDescriptor 。

key
Object

検索する property パラメーターの値。

返品

指定した PropertyDescriptorを持つ行のインデックス。

例外

例

次のコード例は、 Find メソッドを実装する方法を示しています。

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

注釈

このメソッドは、 property パラメーターの値が key パラメーターの値と等しい最初の行を選択します。

このメソッドは、 SupportsSearching が trueされている場合にサポートされます。それ以外の場合、このメソッドは NotSupportedExceptionをスローします。

適用対象