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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Selection and current cell

Thread ID:

Created:

Updated:

Platform:

Replies:

1610 Nov 14,2002 03:21 PM UTC Nov 14,2002 06:35 PM UTC Windows Forms 1
loading
Tags: GridControl
Teodorico Morell
Asked On November 14, 2002 03:21 PM UTC

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.

Administrator [Syncfusion]
Replied On 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();
		}
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;