Behavior

Change default behaviors

Change focus cell move to next row instead of next cell

The property SelectionForwardDirection of worksheet is used to decide where is the next position that focus cell should be moved after finish edit. By default, ReoGrid moves focus cell to next cell in same row.

// move right (next cell)
worksheet.SelectionForwardDirection = SelectionForwardDirection.Right;

164

// move down (cell in the next row)
worksheet.SelectionForwardDirection = SelectionForwardDirection.Down;

165

In addition, by handling the below two events to put the selection in any custom position:

  • Worksheet.SelectionMovedForward (Enter)
  • Worksheet.SelectionMovedBackward (Shift+Enter)

These two events have the property IsCancelled  that is used to prevent the built-in default operations, to move selection to custom positions, use the code like below:

worksheet.SelectionMovedForward += (s, e) => e.IsCancelled = true;
worksheet.SelectionMovedBackward += (s, e) => e.IsCancelled = true;

// move selection to another position
worksheet.SelectionRange = new RangePosition(worksheet.SelectionRange.Row + 1, 0, 1, 1);

Change next position by handling keyboard events

It is able to handle the event BeforeCellKeyDown to receive the event if user pressed any keys on worksheet. Set the IsCancelled property to true to prevent the built-in default operation, and move the selection to any custom position instead.

worksheet.BeforeCellKeyDown += (s, e) =>
{
  if (e.KeyCode == Keys.Enter)
  {
    e.IsCancelled = true;
    // always move to first cell of next row
    worksheet.SelectionRange =
      new RangePosition(worksheet.SelectionRange.Row + 1, 0, 1, 1);
  }
};

Change selection mode

It is possible to change selection mode for every worksheet:

worksheet.SelectionMode = WorksheetSelectionMode.Row;

The following mode are supported:

Enum Value Description
None Do not allow to select anything on worksheet.
Cell Only allow to select single cell.
Range Allow to select cell or range.
Row Always to select one or more entire row at a time.
Column Always to select one or more entire column at a time.

Custom limitation to selection range

The BeforeSelectionRangeChange event fired when user attempts to change the selection. By setting the property IsCancelled of this event argument to prevent the built-in operations.

This event also has the properties that allow user code to change the selection instead of default selected range. The example below shows how to limit the number of rows and columns to a selection operation.

Limit selection range maximum rows and columns

Add a handler to event BeforeSelectionRangeChange:

worksheet.BeforeSelectionRangeChange += worksheet_BeforeSelectionRangeChange;

By changing the selection end position to limit the maximum number of rows to 5:

void worksheet_BeforeSelectionRangeChange(object sender, BeforeSelectionChangeEventArgs e)
{
  int rows = Math.Abs(e.StartRow - e.EndRow);

  if (rows >= 5)
  {
    if (e.EndRow > e.StartRow)
      e.EndRow = e.StartRow + 5 - 1;
    else 
      e.EndRow = e.StartRow - 5 + 1;
  }
}

Disable cell data automatic format

When user inputted data inside cell, ReoGrid try to format the cell and choose a nearest data type for cell format in futures. To disable this auto format behavior, set the worksheet settings to false:

worksheet.SetSettings(WorksheetSettings.Edit_AutoFormatCell, false);

More about worksheet settings, see Settings.

Change percent input method

By default, ReoGrid puts a % symbol at the end of text when user attempts to edit a percent type cell. To disable this behavior, set the worksheet settings to false:

worksheet.SetSettings(WorksheetSettings.Edit_FriendlyPercentInput, false);

More about worksheet settings, see Settings.

Built-in default keyboard operations

See available hot-key list.

Change selection style

Property SelectionStyle of worksheet could be used to change the selection style.

Default style

worksheet.SelectionStyle = ReoGridSelectionStyle.Default;

161

Windows Focus Style

worksheet.SelectionStyle = ReoGridSelectionStyle.FocusRect;

162

Hide selection

It’s also possible to hide the selection by setting to None:

worksheet.SelectionStyle = ReoGridSelectionStyle.None;

163

Show/hide workbook components

Hide sheet tab control

var workbook = grid;

workbook.SetSettings(WorkbookSettings.View_ShowSheetTabControl, false);

Hide scroll bars and headers

workbook.SetSettings(WorkbookSettings.View_ShowScrolls | WorkbookSettings.View_ShowHeaders, false);

Hide row and column headers

var sheet = workbook.CurrentWorksheet;

sheet.SetSettings(WorksheetSettings.View_ShowHeaders, false);

The control shows like below:

30

Hide grid lines

sheet.SetSettings(WorksheetSettings.View_ShowGridLine, false);

31

Disable adjust height of row and width of column by mouse

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

Readonly Mode

In this worksheet read-only mode, all edit operations on this spreadsheet will be disabled.

sheet.SetSettings(WorksheetSettings.Edit_Readonly, true);

All available settings

For full list of settings see Settings.


Next: Reset Control