IBindingList.Find(PropertyDescriptor, Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳給定 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的列的索引。
例外狀況
SupportsSearching 是 false。
範例
以下程式碼範例示範如何實作此 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拋出 。