Back to Devexpress

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

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

latest2.2 KB
Original Source

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

  • Apr 22, 2022

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

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)

Change the SpreadsheetControl’s Background Color

Use the SpreadsheetViewOptions.BackColor property to change the color of the SpreadsheetControl’s non-editable area.

csharp
spreadsheetControl.Options.View.BackColor = Color.FromArgb(0xef, 0xf6, 0xf3);
vb
spreadsheetControl.Options.View.BackColor = Color.FromArgb(&Hef, &Hf6, &Hf3)