Access the Spreadsheet Editor Controls
This topic describes how to access and customize the SpreadsheetControl control used to display Spreadsheet documentsin XAF Windows Forms applications with the Office Module:
Note
XAF does not support the Spreadsheet editor for ASP.NET Core Blazor applications.
Access the WinForms-Specific Control (SpreadsheetControl)
Follow the steps below to access the SpreadsheetControl and restrict the number of visible rows and columns in a worksheet.
- Create a custom ViewController in the WinForms application project (MySolution.Win).
- In the overridden
OnActivatedmethod, get theSpreadsheetServiceControllerand subscribe to itsCustomizeSpreadsheetControlevent. - In the
CustomizeSpreadsheetControl‘s handler, access the SpreadsheetControl and subscribe to its DocumentLoaded event. In the
DocumentLoadedevent handler, use the SetSize method 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 WinSpreadsheetController : 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; spreadsheetControl.DocumentLoaded += SpreadsheetControl_DocumentLoaded; } private void SpreadsheetControl_DocumentLoaded(object sender, System.EventArgs e) { SpreadsheetControl spreadsheetControl = (SpreadsheetControl)sender; Worksheet worksheet = spreadsheetControl.ActiveWorksheet; spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, 5, 10); } }
See Also