The Find( ) and FindRows( ) methods of the DataView search for rows in a DataView using its sort key values. The search values must match the sort key values exactly to return a result; wild card matches are not possible.

The primary difference between the Find( ) and FindRows( ) methods is that Find( ) returns the zero-based index of the first row that matches the search criteria (or -1 if no match is found) while FindRows( ) returns a DataRowView array of all matching rows (or an empty array if no match is found). The DataRow for a DataRowView can be accessed using the DataRow property of the DataRowView .

Before either method can be used, a sort order must be specified or an exception will be raised. You can do this in two ways:

Set the ApplyDefaultSort property of the DataView to true . This automatically creates an ascending sort order based on the primary column or columns of the table. The default sort can be applied only when the Sort property of the DataView is a null reference or an empty string and when the underlying DataTable has a primary key defined. By default, the AutoDefaultSort property is set to false , so it must be explicitly set.

Setting the Sort property of the DataView to a string containing one or more column names followed by nothing, or ASC for an ascending sort, or by DESC for a descending sort. Use commas to separate multiple sort column names.

Both the Find( ) and FindRows( ) methods take a single input argument. This is an object value if the DataView is sorted on a single column or an array of objects containing values for all of the columns defined by the Sort property in the same order as specified by the Sort property.

The Find( ) and FindRows( ) methods perform better than the RowFilter property when a result set from the DataView matching specific criteria is required rather than a dynamic view on the subset of data. This is because setting the RowFilter property of the DataView causes the index for the DataView to be rebuilt, while the Find( ) and FindRows( ) methods use the existing index.