Workbook

Overview

A workbook contains multiple worksheet.

328

Screen component construction as following picture:

215

Control is Workbook

The ReoGrid control itself is a workbook instance.

var workbook = reoGridControl1;

Access worksheet

A workbook contains multiple worksheet, to access current activated worksheet, use CurrentWorksheet property.

var worksheet = reoGridControl.CurrentWorksheet;

To access a specified worksheet by its name or index, use Worksheets collection property:

var sheet1 = reoGridControl.Worksheets[0];
var sheet2 = reoGridControl.Worksheets["Sheet2"];

To change current worksheet, set CurrentWorksheet property to another worksheet instance. This property cannot be set to null.

var anotherWorksheet = reoGridControl.Worksheets["sheet2"];

if (anotherWorksheet != null) 
{
  reoGridControl.CurrentWorksheet = anotherWorksheet;
}

Sheet tab control

Both windows form and WPF edition of ReoGrid provide the built-in sheet tab control:

See Working with built-in sheet tab control.

Worksheet Management

Create worksheet

// create worksheet
var sheet = grid.CreateWorksheet();

// create worksheet with a specified name
var sheet = grid.CreateWorksheet('mysheet');

If the name is ignored, ReoGrid will find and use an available name such as ‘Sheet1’, ‘Sheet2’ … from current workbook automatically.

Add/Insert worksheet

// call method
grid.AddWorksheet(sheet);
grid.InsertWorksheet(1, sheet);

// use collection of worksheet
grid.Worksheets.Add(sheet);
grid.Worksheets.Insert(1, sheet);

High Importance-20 Notice that it is not allowed two worksheets have same name in a workbook.

Find worksheet index

Have a name of worksheet, to find the index of worksheet in a workbook, use GetWorksheetIndex method:

var index = grid.GetWorksheetIndex("sheet2");

Copy worksheet

var sheet2 = grid.CopyWorksheet(0, 1);
var sheet3 = grid.CopyWorksheet("sheet2", 2);

Move worksheet

grid.MoveWorksheet(0, 3);

Get parent workbook

Use Workbook property of worksheet to get parent workbook.

var workbook = grid.Workbook;

Events

Workbook provides the following events:

  • WorksheetCreated
  • WorksheetInserted
  • WorksheetRemoved
  • BeforeWorksheetNameChange
  • WorksheetNameChanged

Reset workbook

To reset a workbook, use Reset method:

workbook.Reset();

Memory Workbook

ReoGrid also provides the memory workbook instance, that is a collection of worksheets without GUI. See Memory workbook.


Next: Multiple Worksheet