BindingSource::Find Method (String^, Object^)
Returns the index of the item in the list with the specified property name and value.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- propertyName
-
Type:
System::String^
The name of the property to search for.
- key
-
Type:
System::Object^
The value of the item with the specified propertyName to find.
Return Value
Type: System::Int32The zero-based index of the item with the specified property name and value.
| Exception | Condition |
|---|---|
| InvalidOperationException | The underlying list is not a IBindingList with searching functionality implemented. |
| ArgumentException | propertyName does not match a property in the list. |
The Find method can only be used when the underlying list is an IBindingList with searching implemented. This method simply refers the request to the underlying list's IBindingList::Find method. For example, if the underlying data source is a DataSet, DataTable, or DataView, this method converts propertyName to a PropertyDescriptor and calls the IBindingList::Find method. The behavior of Find, such as the value returned if no matching item is found, depends on the implementation of the method in the underlying list.
The property name comparison is case-insensitive.
The following example shows how to use the Find method with a DataView. To run this example, paste the code into a Windows Form and call PopulateDataViewAndFind from the form's constructor or Load event-handling method. Your form should import the System.Xml and System.IO namespaces.
Available since 2.0