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.

right click on multiple rows using C#

Thread ID:

Created:

Updated:

Platform:

Replies:

32170 Jul 22,2005 02:43 PM Aug 4,2005 11:16 AM Windows Forms 8
loading
Tags: GridControl
Fang Yan
Asked On July 22, 2005 02:43 PM

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!

Administrator [Syncfusion]
Replied On July 22, 2005 06:46 PM

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

Fang Yan
Replied On July 25, 2005 07: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.

Administrator [Syncfusion]
Replied On July 25, 2005 07: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.

Administrator [Syncfusion]
Replied On July 25, 2005 08: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.

Craig Timmerman
Replied On August 3, 2005 04: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.

Administrator [Syncfusion]
Replied On August 3, 2005 05: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

Craig Timmerman
Replied On August 4, 2005 11: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 > > >

Administrator [Syncfusion]
Replied On August 4, 2005 11: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;
		}
	}
}

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.

;