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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Excel like behavior

Thread ID:

Created:

Updated:

Platform:

Replies:

8506 Nov 10,2003 01:01 AM UTC Nov 10,2003 07:35 PM UTC WinForms 12
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On November 10, 2003 01:01 AM UTC

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.

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

Administrator [Syncfusion]
Replied On 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?

Administrator [Syncfusion]
Replied On 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

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

Administrator [Syncfusion]
Replied On November 10, 2003 12:11 PM UTC

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

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

Administrator [Syncfusion]
Replied On 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?

Administrator [Syncfusion]
Replied On 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.

Administrator [Syncfusion]
Replied On November 10, 2003 03:37 PM UTC

Try this example using a DataBoundGrid.

Administrator [Syncfusion]
Replied On 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.

Administrator [Syncfusion]
Replied On 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

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

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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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

;