[]
Spread for WPF allows you to search for specific content, like text, values, or formulas, in a specified range of cells using the Find method of the IRange interface. This method provides various parameters, such as FindLookIn, LookAt, SearchOrder, SearchDirection, MatchCase, etc. to enhance your search capabilities and get precise results.
Additionally, the FindNext and FindPrevious methods help you locate the next or previous cells that match the same criteria.
The GIF below shows how to search using the FindNext method.
The following example code searches for "0" in the "Order" column and uses the FindNext method to find the next matching value within the defined range of cells.
C#
IRange f;
private void btn_FindNext(object sender, RoutedEventArgs e)
{
if (f == null)
{
// Specify the cell range to search.
f = spreadSheet1.Workbook.Worksheets[0].Cells["H1:H50"];
// Use the Find method to search for '0' in the cell range 'H1:H50'.
f.Find(0, null, FindLookIn.Values, LookAt.Whole, SearchOrder.Rows, SearchDirection.Next, true).Activate();
}
else
{
// Use the FindNext method to find the next matching value in the defined range of cells.
f.FindNext(spreadSheet1.Workbook.Worksheets[0].ActiveCell).Activate();
}
}
VB
Private f As IRange
Private Sub btn_FindNext(sender As Object, e As RoutedEventArgs)
If f Is Nothing Then
' Specify the cell range to search.
f = spreadSheet1.Workbook.Worksheets(0).Cells("H1:H50")
' Use the Find method to search for '0' in the cell range 'H1:H50'.
f.Find(0, Nothing, FindLookIn.Values, LookAt.Whole, SearchOrder.Rows, SearchDirection.[Next], True).Activate()
Else
' Use the FindNext method to find the next matching value in the defined range of cells.
f.FindNext(spreadSheet1.Workbook.Worksheets(0).ActiveCell).Activate()
End If
End Sub