We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Selection and current cell

How can I get this behavior (Excel Like or Project Grid like)? When selecting a range of cells with the mouse or keyboard: 1) Pressing any “Arrow key” clears the selections and moves to the desired cell. 2) Pressing “Enter” the current cell cycles through all the cells in the selections. Thanks.

1 Reply

AD Administrator Syncfusion Team November 14, 2002 06:35 PM UTC

You can probably do this by handling the CurrentCellKeyDown event. Here is a try at this.
private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(this.gridControl1.Selections.Count > 0 
		&& this.gridControl1.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(cc.RowIndex, cc.ColIndex)))
	{
		if(e.KeyCode == Keys.Enter)
		{
			GridRangeInfo range = this.gridControl1.Selections.Ranges.GetRangesContaining(GridRangeInfo.Cell(cc.RowIndex, cc.ColIndex))[0];
			range.ExpandRange(1, 1, this.gridControl1.RowCount, this.gridControl1.ColCount);
			int row = cc.RowIndex + 1;
			int col = cc.ColIndex;

			if(cc.RowIndex + 1 > range.Bottom)
			{
				if(cc.ColIndex < range.Right)
				{
					row = range.Top;
					col++;
				}
				else
				{
					row = range.Top;
					col = range.Left;
				}
			}
			this.gridControl1.CurrentCell.MoveTo(row, col);
			e.Handled = true;
		}
		else
		{
			if(!e.Control && !e.Shift && 
				(e.KeyCode == Keys.Up || e.KeyCode == Keys.Right
				|| e.KeyCode == Keys.Down 
				|| e.KeyCode == Keys.Left))
					this.gridControl1.Selections.Clear();
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon