The worksheet is the primary data container in ReoGrid. Each worksheet provides a grid of cells organized in rows and columns, with row and column headers.

216

The worksheet view comprises three sections:

  • Row Header View โ€” Displays row numbers and allows row selection
  • Column Header View โ€” Displays column letters and allows column selection
  • Cells View โ€” The main data area where cells are displayed and edited

Managing Worksheets

Get the Current Worksheet

var sheet = reoGridControl.CurrentWorksheet;

Change the Current Worksheet

reoGridControl.CurrentWorksheet = anotherWorksheet;

Note: CurrentWorksheet cannot be set to null โ€” the control must always have at least one active worksheet.

Access by Index or Name

var sheet = reoGridControl.Worksheets[1];       // By index
var sheet = reoGridControl.Worksheets["Sheet2"]; // By name

Get Worksheet Index

int index = reoGridControl.GetWorksheetIndex(mysheet);

Change Worksheet Name

sheet.Name = "Sales Data";

Worksheet names must be unique within the same workbook.

Tab Appearance

sheet.NameBackColor = new SolidColor(Color.LightBlue);  // Tab background
sheet.NameTextColor = new SolidColor(Color.DarkBlue);    // Tab text color

Create / Insert / Delete / Move / Copy

See Workbook โ€” Worksheet Management.

Cell Data Access

Method 1: Worksheet Indexer

// Set data
sheet["A1"] = "hello world";
sheet[0, 0] = 10;

// Get data
var value = sheet["A1"];

Method 2: Cell Instance

var cell = sheet.Cells["A1"];
cell.Data = "hello world";

The cell instance provides properties for Data, Formula, Style, Body, and more. See Cell.

Note: Accessing Cells[...] creates a new instance if one doesnโ€™t exist. To check without creating, use GetCell:

var cell = sheet.GetCell("A1");  // Returns null if cell doesn't exist

Method 3: Using Actions (Undo Support)

sheet.DoAction(new SetCellDataAction("A1", "hello world"));

Key Properties

PropertyTypeDescription
NamestringWorksheet name
WorkbookIWorkbookParent workbook
RowCount / RowsintNumber of rows
ColumnCount / ColumnsintNumber of columns
UsedRangeRangePositionRange containing data (read-only)
MaxContentRowintMaximum row with content (read-only)
MaxContentColintMaximum column with content (read-only)
SelectionRangeRangePositionCurrent selection
FocusPosCellPositionCurrent focus cell
ScaleFactorfloatZoom level (1.0 = 100%)
IsFrozenboolWhether worksheet is frozen (read-only)
IsLockedboolWhether worksheet is locked
IsEditingboolWhether a cell is being edited (read-only)
EditingCellCellCurrently editing cell (read-only)
VisibleboolWhether worksheet is visible
IndentSizefloatText indent size
OptionsWorksheetOptionsWorksheet options object

Styles

Set cell styles using SetRangeStyles:

sheet.SetRangeStyles("A1:C3", new WorksheetRangeStyle
{
    Flag = PlainStyleFlag.TextColor,
    TextColor = Color.Green,
});

221

See Cell Style for all style options.

Borders

sheet.SetRangeBorders("A1:C3", BorderPositions.InsideHorizontal,
    new RangeBorderStyle
    {
        Style = BorderLineStyle.Dashed,
        Color = Color.Pink,
    });

222

See Border for all border options.

Rows and Column Headers

Access row and column headers:

var rowHeader = sheet.RowHeaders[0];
var colHeader = sheet.ColumnHeaders[0];
var colHeader = sheet.ColumnHeaders["B"];

See Rows, Columns & Headers for comprehensive header customization.

Show / Hide Headers

sheet.SetSettings(WorksheetSettings.View_ShowRowHeader, false);
sheet.SetSettings(WorksheetSettings.View_ShowColumnHeader, false);

223

See Settings for all settings.

Selection Behavior

Change Selection Forward Direction

// Move down after Enter (instead of right)
sheet.SelectionForwardDirection = SelectionForwardDirection.Down;

Disable Selection

sheet.SelectionMode = WorksheetSelectionMode.None;

Allow/Disallow Resizing

sheet.SetSettings(WorksheetSettings.Edit_AllowAdjustRowHeight, false);
sheet.SetSettings(WorksheetSettings.Edit_AllowAdjustColumnWidth, false);

See Selection for comprehensive selection management.

ReoGrid provides print and export capabilities:

// Export as HTML
sheet.ExportAsHTML(stream);
sheet.ExportAsHTML(stream, "Page Title", exportHeader: true);

224

See Paging and Print for printing details.

Reset

Reset the worksheet to its default state:

sheet.Reset();           // Reset with default size
sheet.Reset(500, 100);   // Reset with 500 rows and 100 columns

Listen for the reset:

sheet.Resetted += (s, e) => Console.WriteLine("Worksheet was reset");

Dispose

Release worksheet resources:

sheet.Dispose();

Feature Guide

FeatureDocumentation
Row/column management, headersRows, Columns & Headers
Multi-row column headersMultiple Row Header
Range operationsRange
Cell mergingMerge Cells
Named rangesNamed Range
Freeze panesFreeze Panes
Selection and focusSelection
Row/column groupingGroup & Outline
Data filteringData Filtering
Conditional stylesConditional Styles
Protection & lockingProtection & Locking
ZoomZoom
Data source bindingData Source
Text searchText Search
All eventsEvents
Settings & optionsSettings
Was this article helpful?