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.

Context Menu

Thread ID:

Created:

Updated:

Platform:

Replies:

22047 Dec 2,2004 02:02 AM Dec 3,2004 03:24 AM Windows Forms 5
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On December 2, 2004 02:02 AM

Hi, I am trying to pop up context menu on the column header and cells of the particular column header of GridDataBoundGrid. On mouse up event i am getting row and column using following method m_GridDataBoundGrid1.PointToRowCol(new Point(e.X,e.Y), out m_LastRow, out m_LastCol); On the column headers context menu is coming properly but on the right click of the cell it doesnt come up. My requirement is to select the cell by left click and show context menu on the right click (Context menu appears when the cell is made deactive) Can you help?

Administrator [Syncfusion]
Replied On December 2, 2004 03:23 AM

The problem is that when a cell is active, the grid does not get the mouse up. Instead the cell control gets it. So, one way to handle this is to subcribe to the cell control''s mouseup event. You can do this dynamically as you move from cell to cell in teh grid''s CurrentCellControlGotFocus event. You would also need to unsubscribe to it in the LostFocus event. Here are some snippets.
private void gridDataBoundGrid1_MouseUp(object sender, MouseEventArgs e)
{
	int row, col;
	if(e.Button == MouseButtons.Right
		&& this.gridDataBoundGrid1.PointToRowCol(new Point(e.X,e.Y), 
		out row, 
		out col))
	{
		ShowMenuFor(row, col);
	}
}
private void currentCell_MouseUp(object sender, MouseEventArgs e)
{
	if(e.Button == MouseButtons.Right)
	{
		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
		ShowMenuFor(cc.RowIndex, cc.ColIndex);
	}
}
private void gridDataBoundGrid1_CurrentCellControlGotFocus(object sender, ControlEventArgs e)
{
	e.Control.MouseUp += new MouseEventHandler(currentCell_MouseUp);
}
private void gridDataBoundGrid1_CurrentCellControlLostFocus(object sender, ControlEventArgs e)
{
	e.Control.MouseUp -= new MouseEventHandler(currentCell_MouseUp);
}
private void ShowMenuFor(int row, int col)
{
	MessageBox.Show(string.Format("menu for ({0},{1}", row, col));
}

Administrator [Syncfusion]
Replied On December 2, 2004 05:26 AM

Thanks for the reply But there is not current cell mouse up event for DataBoundGrid when i specified cell mouse event i got following compilation error SlbWFTIPretestListingUI.m_GridDataBoundGrid1_CellMouseUp(object, Syncfusion.Windows.Forms.Grid.GridCellMouseEventArgs)'' does not match delegate ''void System.Windows.Forms.MouseEventHandler(object, System.Windows.Forms.MouseEventArgs)'' Can you help? >The problem is that when a cell is active, the grid does not get the mouse up. Instead the cell control gets it. So, one way to handle this is to subcribe to the cell control''s mouseup event. You can do this dynamically as you move from cell to cell in teh grid''s CurrentCellControlGotFocus event. You would also need to unsubscribe to it in the LostFocus event. Here are some snippets. >
>private void gridDataBoundGrid1_MouseUp(object sender, MouseEventArgs e)
>{
>	int row, col;
>	if(e.Button == MouseButtons.Right
>		&& this.gridDataBoundGrid1.PointToRowCol(new Point(e.X,e.Y), 
>		out row, 
>		out col))
>	{
>		ShowMenuFor(row, col);
>	}
>}
>private void currentCell_MouseUp(object sender, MouseEventArgs e)
>{
>	if(e.Button == MouseButtons.Right)
>	{
>		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
>		ShowMenuFor(cc.RowIndex, cc.ColIndex);
>	}
>}
>private void gridDataBoundGrid1_CurrentCellControlGotFocus(object sender, ControlEventArgs e)
>{
>	e.Control.MouseUp += new MouseEventHandler(currentCell_MouseUp);
>}
>private void gridDataBoundGrid1_CurrentCellControlLostFocus(object sender, ControlEventArgs e)
>{
>	e.Control.MouseUp -= new MouseEventHandler(currentCell_MouseUp);
>}
>private void ShowMenuFor(int row, int col)
>{
>	MessageBox.Show(string.Format("menu for ({0},{1}", row, col));
>}
>

Administrator [Syncfusion]
Replied On December 2, 2004 06:48 AM

The currentCell_MouseUp method is defined in the above code. It is not a member of anything except the form where it resides. It is the delegate that will be used to handle the active cell control''s MouseUp event. So, I made its signature to be that of a Control.MouseUp event handler so it can be used as a Control.MouseUp handler. Here is the working sample from where I copied the above code. WindowsApplication11_1762.zip

Administrator [Syncfusion]
Replied On December 2, 2004 07:15 PM

It worked. In sample attached,there is one extra row created .Can you tell the reason and how can we avoid creating that extra row? i have the same issue of extra row in my application Secondly, i have requirement of Multi-selection of cells by left click with the control key held (same as Excel) or click and drag. Is there any property for that? >The currentCell_MouseUp method is defined in the above code. It is not a member of anything except the form where it resides. It is the delegate that will be used to handle the active cell control''s MouseUp event. So, I made its signature to be that of a Control.MouseUp event handler so it can be used as a Control.MouseUp handler. > >Here is the working sample from where I copied the above code. > >WindowsApplication11_1762.zip > >

Administrator [Syncfusion]
Replied On December 3, 2004 03:24 AM

That is the AddNew row where you users can enter new a record if you want them to be able to add new records in this manner. It is an MS-Access type feature (it is part of the Windows Forms DataGrid also.) If you do not want it, set this.gridDataBoundGrid1.EnableAddNew = false;.

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.

;