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.

Excel like behavior

Thread ID:

Created:

Updated:

Platform:

Replies:

8506 Nov 9,2003 08:01 PM Nov 10,2003 02:35 PM Windows Forms 12
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On November 9, 2003 08:01 PM

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 01:15 AM

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 01:19 AM

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 05:11 AM

> 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 06:01 AM

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 07:11 AM

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

Administrator [Syncfusion]
Replied On November 10, 2003 07:56 AM

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 10:06 AM

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 10:33 AM

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 10:37 AM

Try this example using a DataBoundGrid.

Administrator [Syncfusion]
Replied On November 10, 2003 11:05 AM

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 01:05 PM

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 02:35 PM

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.

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.

;