Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example creates a workbook with three sheets. When the user starts to change the active sheet, the SheetChanging event occurs, and the application checks to see if the new sheet is sheet 3. If the new sheet is sheet 3, the sheet change is canceled.

C++

BOOL CAboutDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    // Set number of sheets
    m_Spread.SetSheetCount(3);
}

void CAboutDlg::OnSheetChangingFpspread1(short OldSheet, short NewSheet, VARIANT FAR* Cancel)
{
    // If new sheet is 3, set cancel to true
    if (NewSheet == 3)
    {
    Cancel->boolVal = VARIANT_TRUE;
    }
}

Visual Basic

Private Sub Form_Load()
    ' Set number of sheets
    fpSpread1.SheetCount = 3
End Sub

Private Sub fpSpread1_SheetChanging(ByVal OldSheet As Integer, ByVal NewSheet As Integer, Cancel As Variant)
    ' Show old and new sheet numbers in immediate window
    Debug.Print OldSheet, NewSheet
    ' Prevent the user from changing to sheet 3
    If NewSheet = 3 Then
        Cancel = True
    End If
End Sub

Copyright © GrapeCity, inc. All rights reserved.