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
close icon

shift-space select row

Again trying to make the grid act like excel, i put the following code in grid_KeyDown: if ( e.KeyCode == Keys.Space && e.Modifiers == Keys.Shift ) { grid.EndEdit(); GridRangeInfoList rowSelections = new GridRangeInfoList(); foreach ( GridRangeInfo range in grid.Selections.Ranges ) { GridRangeInfo rows = GridRangeInfo.Cells(range.Top, 1, range.Bottom, grid.ColCount); rowSelections.Add(rows); } grid.Selections.Clear(); foreach ( GridRangeInfo range in rowSelections ) { grid.Selections.SelectRange(range, true); } e.Handled = true; } which kind of does what I want, but ends up typing a Space key anyway. Suggestions?

1 Reply

AD Administrator Syncfusion Team August 5, 2004 10:17 PM UTC

I think you will have to derive the grid and override virtual methods to avoid processing the space. Here is a first try at this.
public class MyGridControl : GridControl
{
	protected override bool ProcessDialogKey(Keys key)
	{
		if ( (key & Keys.KeyCode) == Keys.Space && Control.ModifierKeys == Keys.Shift )
		{
			Selections.Clear();
			Selections.SelectRange(GridRangeInfo.Row(this.CurrentCell.RowIndex), true);
			return true;
		}
		else
			return base.ProcessDialogKey (key);
	}
	
	protected override void OnCurrentCellMoved(GridCurrentCellMovedEventArgs e)
	{
		if(this.CurrentCell.MoveFromRowIndex != this.CurrentCell.MoveToRowIndex)
		{
			GridRangeInfo oldRange = GridRangeInfo.Row(this.CurrentCell.MoveFromRowIndex);
			if(Selections.Ranges.ActiveRange.Equals(oldRange))
			{
				Selections.Clear();
				Selections.SelectRange(GridRangeInfo.Row(this.CurrentCell.MoveToRowIndex), true);
			}
		}
		base.OnCurrentCellMoved (e);
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon