Back to Devexpress

How to: Restrict the Number of Visible Rows and Columns in a Worksheet

wpf-119999-controls-and-libraries-spreadsheet-examples-rows-and-columns-how-to-restrict-the-number-of-visible-rows-and-columns-in-a-worksheet.md

latest1.5 KB
Original Source

How to: Restrict the Number of Visible Rows and Columns in a Worksheet

  • Jun 25, 2019

This example demonstrates how to use the WorksheetDisplayArea.SetSize method to restrict the number of rows and columns the SpreadsheetControl displays in a worksheet.

In particular, the code snippet below shows how to set the active worksheet’s visible area to the used range the Worksheet.GetUsedRange method returns.

csharp
// Access the active worksheet.
Worksheet worksheet = spreadsheetControl.ActiveWorksheet;
// Get the range containing non-empty cells.
CellRange usedRange = worksheet.GetUsedRange();
// Restrict the worksheet's visible area to the used range.
spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, usedRange.ColumnCount, usedRange.RowCount);
vb
' Access the active worksheet.
Dim worksheet As Worksheet = spreadsheetControl.ActiveWorksheet
' Get the range containing non-empty cells.
Dim usedRange As CellRange = worksheet.GetUsedRange()
' Restrict the worksheet's visible area to the used range.
spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, usedRange.ColumnCount, usedRange.RowCount)

The following image shows the result: