How to make right-click activate AND change selection?

I want right-click behavior just like Excel - when you right click within the selection, neither the current cell nor the selection will change, just a pop-up will appear. However when you right-click outside the selection, it should select the cell under the cursor and also make it active. I have a grid with ExcelLikeCurrentCell set to true, and hte following right-click handler: private void grid_MouseDown(object sender, MouseEventArgs e) { if ( e.Button == MouseButtons.Right ) { GridRangeInfo clickedRange = grid.PointToRangeInfo(new Point(e.X,e.Y)); bool clickedInSelection = false; if ( clickedRange != null ) { foreach ( GridRangeInfo info in grid.Selections.Ranges ) { if ( info.IntersectsWith(clickedRange) ) { clickedInSelection = true; break; } } if ( !clickedInSelection ) { grid.Selections.Clear(true); grid.Selections.SelectRange(clickedRange, true); grid.CurrentCell.Activate(clickedRange.Top, clickedRange.Left, GridSetCurrentCellOptions.SetFocus); } } } } Also I have a Syncfusion XPMenu popup tied to the grid. However when I right-click outside the selection, it changes the selection but doesnt appear to change the current cell also. How can I get it to do this? Thanks - Daniel

2 Replies

AD Administrator Syncfusion Team August 5, 2004 06:52 PM UTC

Instead of grid.Selections.Clear(true); grid.Selections.SelectRange(clickedRange, true); grid.CurrentCell.Activate(clickedRange.Top, clickedRange.Left, GridSetCurrentCellOptions.SetFocus); try grid.Selections.Clear(true); grid.CurrentCell.MoveTo(clickedRange.Top, clickedRange.Left, GridSetCurrentCellOptions.SetFocus);


DC Daniel Chait August 5, 2004 07:39 PM UTC

Thanks that did the trick.

Loader.
Up arrow icon