Example
The following example creates a form with a sheet users can search. Users click the column or row to search, type a search string in the text box, and select search options. When users click the Search button, the sheet searches the specified column or row for the string. If found, the cell containing the string is moved into view in the upper-left corner of the sheet.
C++
void CTestprojDlg::OnButton2()
{
long ret;
// Search column unless row is specified
if (IsDlgButtonChecked(IDC_CHECK3) == 0) {
// Search for exact match unless partial match specified
if (IsDlgButtonChecked(IDC_CHECK4) == 0 )
ret = m_Spread1.SearchCol(m_Spread1.GetActiveCol(), 0, -1, (LPCTSTR)m_SearchString, 0);
else
ret = m_Spread1.SearchCol(m_Spread1.GetActiveCol(), 0, -1, (LPCTSTR)m_SearchString, 2);
// Move cell with search text into upper left, if found
if (ret != -1)
m_Spread1.ShowCell(m_Spread1.GetActiveCol(), ret, 0);
}
else {
// Search row as specified, searching for exact match
// unless partial match specified
if (IsDlgButtonChecked(IDC_CHECK4) == 0 )
ret = m_Spread1.SearchRow(m_Spread1.GetActiveRow(), 0, -1, (LPCTSTR)m_SearchString, 0);
else
ret = m_Spread1.SearchRow(m_Spread1.GetActiveRow(), 0, -1, (LPCTSTR)m_SearchString, 2);
// Move cell with search text into upper left, if found
if (ret != -1)
m_Spread1.ShowCell(ret, m_Spread1.GetActiveRow(), 0);
}
}
Visual Basic
Private Sub Command1_Click()
Dim ret As Long
' Search column unless row is specified
If Check1.Value = False Then
' Search for exact match unless partial match specified
If Check2.Value = False Then
ret = fpSpread1.SearchCol(fpSpread1.ActiveCol, 0, -1, Text1.Text, SearchFlagsNone)
Else
ret = fpSpread1.SearchCol(fpSpread1.ActiveCol, 0, -1, Text1.Text, SearchFlagsPartialMatch)
End If
' Move cell with search text into upper left, if found
If ret <> -1 Then
fpSpread1.ShowCell fpSpread1.ActiveCol, ret, PositionUpperLeft
End If
Else
' Search row as specified, searching for exact match
' unless partial match specified
If Check2.Value = False Then
ret = fpSpread1.SearchRow(fpSpread1.ActiveRow, 0, -1, Text1.Text, SearchFlagsNone)
Else
ret = fpSpread1.SearchRow(fpSpread1.ActiveRow, 0, -1, Text1.Text, SearchFlagsPartialMatch)
End If
' Move cell with search text into upper left, if found
If ret <> -1 Then
fpSpread1.ShowCell ret, fpSpread1.ActiveRow, PositionUpperLeft
End If
End If
End Sub
Private Sub Form_Load()
' Set up search input
Frame1.Caption = "Search Setup"
Text1.Text = ""
Command1.Caption = "Search"
Check1.Caption = "Search Row"
Check2.Caption = "Partial Matches Allowed"
Label1.Caption = "Click the column or row you want to search. Then type your search string in the text box. Choose an option, if you want, and then click Search."
End Sub