Help in right click menu in c#

  • Thread starter Thread starter John Rajendran
  • Start date Start date
J

John Rajendran

HI there,
I need to make the functionality of right clicking on a datagrid cell and try to invoke some menu driven code. It could be a file opening, file saving or my own event driven code. Is this possible, if so can someone help me with some sample code.
Thanks
john


___
Newsgroups brought to you courtesy of www.dotnetjohn.com
 
Hi John,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add context menu on right
click. If there is any misunderstanding, please feel free to let me know.

I think we can handle the right click event of each cell's control. Here is
an example:

private void Form1_Load(object sender, System.EventArgs e)
{
this.dataGrid1.ControlAdded +=new
ControlEventHandler(dataGrid1_ControlAdded);
}

private void dataGrid1_ControlAdded(object sender, ControlEventArgs e)
{
if(e.Control is TextBox)
e.Control.MouseUp +=new MouseEventHandler(Control_MouseUp);
}

private void Control_MouseUp(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
MessageBox.Show("Right Clicked!");
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top