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

Excel like behavior

How can I accomplish Excel like selection behavior, where if I have selected a range and move (click) to any other cell the range is cleared? I played around ExcelLike properties in GDBG but coudn't replicate Excel behavior. Thanks in advance Jose.

12 Replies

AD Administrator Syncfusion Team November 10, 2003 06:15 AM UTC

Exactly what behavior do you want? When I bring up Excel and select a range, if I click to another cell in the selected range or click to another cell outside the selected range, in either case I see the original selection go away. To maintain the selection, I have to hold down the control key as I click. This is how the grid behaves by default as well. You can probably get whatever behavior you want by handling the SelectionsChanging event. Here is sample code that retains the selection (without the control key) as long as you click within the currently selcted range.
private void grid_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
	int row, col;
	GridRangeInfoList rangeList;
	Point pt = this.grid.PointToClient(Control.MousePosition);
	if(e.Range.IsEmpty && Control.MouseButtons == MouseButtons.Left
		&& this.grid.PointToRowCol(pt, out row, out col, -1)
		&& this.grid.Selections.GetSelectedRanges(out rangeList, false)
		&& rangeList.AnyRangeContains(GridRangeInfo.Cell(row, col)))
	{
		e.Cancel = true;
	}
}


AD Administrator Syncfusion Team November 10, 2003 06:19 AM UTC

I think I misread your question. Are you saying that clicking elsewhere does not remove the current selections? It should. What version of our libraries are you using? If you just drop a GridControl on a form in a sample project. do you see this problem?


AD Administrator Syncfusion Team November 10, 2003 10:11 AM UTC

> I think I misread your question. Are you saying that clicking elsewhere does not remove the current selections? > > It should. What version of our libraries are you using? If you just drop a GridControl on a form in a sample project. do you see this problem? > Clicking is not the problem. When I move to another cell using keyboard it is. Thanks


AD Administrator Syncfusion Team November 10, 2003 11:01 AM UTC

Try handling CurrentCellMoved and clearing the selections there.
private void gridMessages_CurrentCellMoved(object sender, GridCurrentCellMovedEventArgs e)
{
	this.gridMessages.Selections.Clear();
}


AD Administrator Syncfusion Team November 10, 2003 12:11 PM UTC

Opppsss. For some reason I cannot select the first row.


AD Administrator Syncfusion Team November 10, 2003 12:56 PM UTC

Try this code in the event.
GridCurrentCell cc = this.gridMessages.CurrentCell;
if(cc.HasCurrentCell && cc.RowIndex > 0 && cc.ColIndex > 0)
	this.gridMessages.Selections.Clear();


AD Administrator Syncfusion Team November 10, 2003 03:06 PM UTC

It doesn't seen to be related to the first row only, wherever you start doing the selection, first row selected will select only the first column. Any other recommendation?


AD Administrator Syncfusion Team November 10, 2003 03:33 PM UTC

I don't see the problem in attached sample. Do you? Have you set some styles with style.Enabled = false? If so, this will interfere with selections if you try to mouse down on a disabled cell.


AD Administrator Syncfusion Team November 10, 2003 03:37 PM UTC

Try this example using a DataBoundGrid.


AD Administrator Syncfusion Team November 10, 2003 04:05 PM UTC

I can mousedown on Code0 and drag to to 4 in the price column and I see then full rectangle highlighted (except for the current cell which is part of the selection, but not highlighted). This is teh same behavior I see in Excel where the initial mousedown cell is not included in the highlighted range. Attached is the picture I see. If you are seeing something diffferent, what version are you using. I am using a private build, 1.6.1.8.


AD Administrator Syncfusion Team November 10, 2003 06:05 PM UTC

Try to select the first 4 rows, draging from the row header. I am using 1.6.1.9


AD Administrator Syncfusion Team November 10, 2003 07:35 PM UTC

Instead of CurrentCellMoved, try KeyDown.
private void gridDataBoundGrid1_KeyDown(object sender, KeyEventArgs e)
{
	if((e.Modifiers & Keys.Shift) == 0)
	         this.gridDataBoundGrid1.Selections.Clear();
}

Loader.
Up arrow icon