The requested page is not available for the requested platform. You are viewing the content for Default platform.

Access the Spreadsheet Control

This topic describes how to access and customize the SpreadsheetControl object in WinForms applications that use the Office Module. The steps below demonstrate how to restrict the number of visible rows and columns in a worksheet.

  1. Create a custom ViewController in the WinForms module project.
  2. In the overridden OnActivated method, get the SpreadsheetServiceController and subscribe to its CustomizeSpreadsheetControl event.
  3. In the CustomizeSpreadsheetControl's handler, use the SetSize to specify the number of visible rows and columns for an active worksheet.

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Office.Win;
    using DevExpress.Spreadsheet;
    using DevExpress.XtraSpreadsheet;
    // ...
    public class CustomSpreadsheetController : ViewController {
        protected override void OnActivated() {
            base.OnActivated();
            SpreadsheetServiceController controller = Frame.GetController<SpreadsheetServiceController>();
            if(controller != null) {
                controller.CustomizeSpreadsheetControl += Controller_CustomizeSpreadsheetControl;
            }
        }
        private void Controller_CustomizeSpreadsheetControl(object sender, CustomizeSpreadsheetEventArgs e) {
            SpreadsheetControl spreadsheetControl = ((SpreadsheetPropertyEditor)sender).SpreadsheetControl;
            Worksheet worksheet = spreadsheetControl.ActiveWorksheet;
            spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, 5, 10);
        }
    }