Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
By clicking right button from mouse on the gridview it should display call, email options in web application?
Posted
Updated 8-May-12 23:20pm
v2
Comments
Sandeep Mewara 9-May-12 12:35pm    
And what is the question? Issue? What did you try?

1 solution

Attaching mouse click event to specific controls or you can write something to attach to all controls by iteration through the form's Controls collection.

C#
label1.MouseClick += new MouseEventHandler(control_RightMouseClick);
gridview1.MouseClick += new MouseEventHandler(control_RightMouseClick);


Then perform different operations or show different context menu for different controls

C#
if (e.Button != MouseButtons.Right)
   {
       return;
   }
   if (sender.GetType().IsSubclassOf(typeof(Control)))
   {
       Control formControl = (Control)sender;
       switch (formControl.Name)
       {
           case "label1":
               //do something
               contextMenuStrip1.Show(formControl, e.Location);
               break;
           case "gridview1":
               //do something else
               contextMenuStrip2.Show(formControl, e.Location);
               break;
           default:
               //do something else or return or show default context menu
               contextMenuStrip_default.Show(formControl, e.Location);
               break;
       }
   }

   return;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900