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拋出 。

適用於