protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (this.IsValidCell(this.FocusedCell))
{
if (this.IsReservedKey(e.KeyData))
{
Keys key = e.KeyData & Keys.KeyCode;
if (key == Keys.Up || key == Keys.Down || key == Keys.Left || key == Keys.Right)
{
#region Arrow keys
CellPos nextCell;
if (key == Keys.Up)
{
nextCell = this.FindNextVisibleCell(this.FocusedCell, this.FocusedCell.Row > 0, false, false, false, true);
}
else if (key == Keys.Down)
{
nextCell = this.FindNextVisibleCell(this.FocusedCell, this.FocusedCell.Row < this.RowCount - 1, true, false, false, true);
}
else if (key == Keys.Left)
{
nextCell = this.FindNextVisibleCell(this.FocusedCell, false, false, false, true, true);
}
else
{
nextCell = this.FindNextVisibleCell(this.FocusedCell, false, true, false, true, true);
}
if (nextCell != CellPos.Empty)
{
nextCell = ResolveColspan(nextCell);
this.FocusedCell = nextCell;
if ((e.KeyData & Keys.Modifiers) == Keys.Shift && this.MultiSelect)
{
this.TableModel.Selections.AddShiftSelectedCell(this.FocusedCell);
}
else
{
this.TableModel.Selections.SelectCell(this.FocusedCell);
}
}
#endregion
}
else if (e.KeyData == Keys.PageUp)
{
#region Page Up
if (this.RowCount > 0)
{
int i = GetNewIndexFromPageUp(); ;
CellPos temp = new CellPos(i, this.FocusedCell.Column); ;
CellPos nextCell = this.FindNextVisibleCell(temp, true, false, true, false, true);
if (nextCell != CellPos.Empty)
{
this.FocusedCell = nextCell;
this.TableModel.Selections.SelectCell(this.FocusedCell);
}
}
#endregion
}
else if (e.KeyData == Keys.PageDown)
{
#region Page Down
if (this.RowCount > 0)
{
int i = GetNewIndexFromPageDown(); ;
CellPos temp = new CellPos(i, this.FocusedCell.Column);
CellPos nextCell = this.FindNextVisibleCell(temp, true, false, true, false, true);
if (nextCell != CellPos.Empty)
{
this.FocusedCell = nextCell;
this.TableModel.Selections.SelectCell(this.FocusedCell);
}
}
#endregion
}
else if (e.KeyData == Keys.Home || e.KeyData == Keys.End)
{
#region Home, End
if (this.RowCount > 0)
{
CellPos nextCell;
if (e.KeyData == Keys.Home)
{
nextCell = this.FindNextVisibleCell(CellPos.Empty, true, true, true, true, true);
}
else
{
nextCell = this.FindNextVisibleCell(new CellPos(this.RowCount - 1, this.TableModel.Rows[this.RowCount - 1].Cells.Count), true, false, true, true, true);
}
if (nextCell != CellPos.Empty)
{
this.FocusedCell = nextCell;
this.TableModel.Selections.SelectCell(this.FocusedCell);
}
}
#endregion
}
}
else
{
// check if we can start editing with the custom edit key
if (e.KeyData == this.CustomEditKey &&
((this.EditStartAction & EditStartAction.CustomKey) == EditStartAction.CustomKey))
{
this.EditCell(this.FocusedCell);
return;
}
// send all other key events to the cell's renderer
// for further processing
this.RaiseCellKeyDown(this.FocusedCell, e);
}
}
else
{
if (this.FocusedCell == CellPos.Empty)
{
#region Cell is Empty
Keys key = e.KeyData & Keys.KeyCode;
if (this.IsReservedKey(e.KeyData))
{
if (key == Keys.Down || key == Keys.Right)
{
CellPos nextCell;
if (key == Keys.Down)
{
nextCell = this.FindNextVisibleCell(this.FocusedCell, true, true, true, false, true);
}
else
{
nextCell = this.FindNextVisibleCell(this.FocusedCell, false, true, true, true, true);
}
if (nextCell != CellPos.Empty)
{
this.FocusedCell = nextCell;
if ((e.KeyData & Keys.Modifiers) == Keys.Shift && this.MultiSelect)
{
this.TableModel.Selections.AddShiftSelectedCell(this.FocusedCell);
}
else
{
this.TableModel.Selections.SelectCell(this.FocusedCell);
}
}
}
}
#endregion
}
}
}