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

right click on multiple rows using C#

I have a question about right-click event handling. What I want to achieve is selecting multiple rows in data grid first, and then right clicking on them to display a context menu. But what I get right now is all the rows are unselected right after right clicking. I would appreciate if you could give me a sample code that will allow me to right click on multiple rows, and display a context menu. I’m using the Essential Suite 2.1.0.9 version. Thanks a lot!

8 Replies

AD Administrator Syncfusion Team July 22, 2005 05:46 PM

this.gridDataBoundGrid1.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left; This should prevent the right button from affecting any selections.


FY Fang Yan July 25, 2005 06:46 AM

Hi, In my grid I don''t have any function called "gridDataBoundGrid1", or any similar property. So, can you please explain who can I go about it? Thanks! > >this.gridDataBoundGrid1.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left; > >This should prevent the right button from affecting any selections.


AD Administrator Syncfusion Team July 25, 2005 06:50 AM

Never mind, I think its just the name of the grid. Let me try this. Thanks > >Hi, >In my grid I don''t have any function called "gridDataBoundGrid1", or any similar property. So, can you please explain who can I go about it? > >Thanks! > > >> >>this.gridDataBoundGrid1.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left; >> >>This should prevent the right button from affecting any selections.


AD Administrator Syncfusion Team July 25, 2005 07:01 AM

Thanks a lot for your help! I think its working now. > >this.gridDataBoundGrid1.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left; > >This should prevent the right button from affecting any selections.


CT Craig Timmerman August 3, 2005 03:03 PM

I am having the same problem and while your solution fixes the problem in one way, it does not allow me to get the same behavior as excel. Excel allows me to right click on a cell which makes it active and pops up the context menu. When you right click in the header column of a selected row in excel, it keeps the row selected and pops up the context menu. This is the behavior I would like to have. > >this.gridDataBoundGrid1.Model.Options.SelectCellsMouseButtonsMask = MouseButtons.Left; > >This should prevent the right button from affecting any selections.


AD Administrator Syncfusion Team August 3, 2005 04:10 PM

You can try handling the SelectionChanging event and canceling it if you are right-clicking in a selection. http://www.syncfusion.com/Support/user/uploads/GC_RightClick_72d62dc5.zip


CT Craig Timmerman August 4, 2005 10:04 AM

That is closer to what I need. However, even if the cell is part of the selection, it still activates the cell (which excel doesn''t do), but it does leave the rest of the selection alone. >You can try handling the SelectionChanging event and canceling it if you are right-clicking in a selection. > >http://www.syncfusion.com/Support/user/uploads/GC_RightClick_72d62dc5.zip > > >


AD Administrator Syncfusion Team August 4, 2005 10:16 AM

You can additionally handle CurrentCellDeactivating to avoid this.
private bool lockForForMouseUp = false;
private void gridControl1_CurrentCellDeactivating(object sender, CancelEventArgs e)
{
	if(lockForForMouseUp)
	{
		e.Cancel = true;
		lockForForMouseUp = false;
	}
	else if(Control.MouseButtons == MouseButtons.Right)
	{
		int row, col;
		Point pt = this.gridControl1.PointToClient(Control.MousePosition);
		if(this.gridControl1.PointToRowCol(pt, out row, out col)
			&& this.gridControl1.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(row, col)))
		{
			e.Cancel = true;
			lockForForMouseUp = true;
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon