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 Context Menu Location

Hi, Now that you''ve solved my previous problem, I noticed another issue that I can''t seem to figure out. I''ve got the Right Click context menu coming up fine when the user Right clicks on the GridControl and the SelectCellsMouseButtonsMask is set and working great. However, if the location where the user happens to right click is on the area of the grid that has no cells (say, way off to the right in the blank area) they still get the context menu (which makes no sense to me). Is there anyway to suppress the context menu popup when the right click is NOT on selected cells? TIA,

3 Replies

AD Administrator Syncfusion Team February 19, 2004 05:41 PM UTC

If you are using something lik eth etechique in this KB, http://www.syncfusion.com/Support/article.aspx?id=10054, you can check to see if you are over a row, col before showing the menu.
private void gridControl1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
	if(e.Button == MouseButtons.Right)
		Point clickPoint = gridControl1.PointToClient(Cursor.Position);
		int rowIndex, colIndex;
		if(this.gridControl1.PointToRowCol(clickPoint, out rowIndex, out colIndex, -1))
			//make sure there is a selections of some type
			Syncfusion.Windows.Forms.Grid.GridRangeInfoList rangeList = null;
			//if no selections or current cell, use the rightclick point
			if(!gridControl1.Selections.GetSelectedRanges(out rangeList, true))
				gridControl1.CurrentCell.Activate(rowIndex, colIndex);
			contextMenu1.Show(gridControl1, clickPoint);

JB John Bowm February 19, 2004 07:18 PM UTC

Clay, Thanks again for the help. However, I still can''t make it work implementing your code. When the following line fails, the context menu still appears even though the routine exits :(. What gives? if(this.gridControl1.PointToRowCol(clickPoint, out rowIndex, out colIndex, -1)) TIA, John

AD Administrator Syncfusion Team February 19, 2004 08:21 PM UTC

Are you setting the ContextMenu property of the grid? If so, the .Net Framework will display the menu when ever you rightclick on the control (whether you are over a grid cell or not). The KB techniquw does not set the grid''s ContextMenu property. Instead, it explicitly calls contextMenu1.Show to display the menu, and does not rely on the framework to display it.

Live Chat Icon For mobile
Up arrow icon