This project is read-only.


Range specified by a start position and an end position, a smallest region must contain at least one cell. Range is not a merged cell, it is a logical region used to locate in spreadsheet. Two ranges can have some intersected regions.


Struct ReoGridRange contains the numeric information to locate a range in spreadsheet. ReoGridRange is grid control no associated, it cannot keep any data or styles. ReoGridRange could be created with the following 4 arguments:
  • Number of row of start position
  • Number of column of start position
  • Number of rows
  • Number of columns
Notice that number of row, number of column is zero-based index refer to the position of spreadsheet.
// create range start at 4,2 and contains 9 rows and 5 columns
var range = new ReoGridRange(4, 2, 9, 5);

Properties of ReoGridRange are used to get information from a range struct:
Property Desc
range.Row number of row of the start position
range.Col number of column of the start position
range.Rows number of rows contained in this range
range.Cols number of columns contained in this range
range.Row2 number of row of the end position
range.Col2 number of column of the end position
range.IsEmpty check whether this range is empty

And some method are available to a ReoGridRange struct:
range.Contains(ReoGridPos)           // check whether range contains specified position
range.Equals(ReoGridRange)           // compare to another range
range.Offset(int rows, int cols)     // move range by n rows and n columns offset

Get a safe range

Sometimes range might outs of the maximum rows of grid, get a checked and safe region by using this method:
var fixedRange = grid.FixRange(range);   // get a fixed range

Reference Range

From v0.8.6, another object for range is imported into ReoGrid, called ReferenceRange, the difference to the ReoGridRange is:
  • ReoGridRange is struct, grid control no associated. ReoGridRange contains the numeric information to describe a logical range
  • ReferenceRange is object, grid control associated. ReferenceRange is always created from an instance of grid control, and it keeps a pointer to the grid instance.

Define named range

From v0.8.6, it is possible to define a name for a range. After a range with a specified name is added into spreadsheet, an object of the type NamedRange will be returned from grid control. NamedRange is inherited from ReferenceRange.

For example:
// define named range start (2,2), it contains 4 columns
grid.DefineNamedRange("header", new ReoGridRange(2, 2, 1, 4));

// set header text inside range named 'header'
grid["header"] = new object[] { "Name", "Age", "Birthday", "Email" };
Text displayed inside 4 columns are added by a named range.

Convert ReferenceRange to ReoGridRange

Anytime, A ReferenceRange can be implicitly converted to a ReoGridRange, for example:
// define named range start (2,2), it contains 4 columns
NamedRange namedRange = grid.DefineNamedRange("header", new ReoGridRange(2, 2, 1, 4));

// SelectionRange needs a ReoGridRange struct
grid.SelectionRange = namedRange;

Set spreadsheet data via ReferenceRange

Since reference range keeps a reference to the grid control, it is possible set data into range instead of control API call.
namedRange.Data = new object[] { "Product", "Unit Price", "Quantity", "Extended Price" };

Merge a range

About merging range refer to Merge and unmerge.

Next: Border

Last edited Apr 17, 2014 at 2:58 PM by unvell, version 12