IBindingList.Find(PropertyDescriptor, Object) Método
Definição
Retorna o índice da linha que tem o PropertyDescriptor determinado.Returns the index of the row that has the given 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
Parâmetros
- property
- PropertyDescriptor
O PropertyDescriptor no qual pesquisar.The PropertyDescriptor to search on.
- key
- Object
O valor do parâmetro property a pesquisar.The value of the property parameter to search for.
Retornos
O índice da linha que tem o PropertyDescriptor determinado.The index of the row that has the given PropertyDescriptor.
Exceções
SupportsSearching é false.SupportsSearching is false.
Exemplos
O exemplo de código a seguir demonstra como implementar o Find método.The following code example demonstrates how to implement the Find method.
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
Comentários
Esse método selecionará a primeira linha em que o valor do property parâmetro é igual ao valor do key parâmetro.This method will select the first row where the value of the property parameter equals the value of the key parameter.
Esse método terá suporte se SupportsSearching for true , caso contrário, esse método lançará um NotSupportedException .This method is supported if SupportsSearching is true, otherwise this method throws a NotSupportedException.