Home / Community & Support / Knowledge Base / RadControls for WinForms / GridView / RadGridView Custom Context Menu

RadGridView Custom Context Menu

Article Info

Rating: 5

Article information

Article relates to

 RadGridView Custom Context Menu

Created by

 Kiril Matev

Last modified

 April 2, 2008

Last modified by

 Kiril Matev



HOW-TO

Use a custom context menu in RadGridView for WinForms

SOLUTION

RadGridView provides a straightforward way to use custom context menus, instead of the default one. This context menu will appear everytime the user right-clicks the RadGridView, regardless of the element of the control they click.

Start by creating the context menu, initializing its items, and subscribing for the events that you want to handle to achieve the desired behavior.

            RadDropDownMenu contextMenu = new RadDropDownMenu();     
            RadMenuItem rmi1 = new RadMenuItem("Item 1");     
            rmi1.ForeColor = Color.Red;     
            rmi1.Click += new EventHandler(rmi1_Click);     
    
            RadMenuItem rmi2 = new RadMenuItem("Item 2");     
            rmi2.Click += new EventHandler(rmi2_Click);     
    
            contextMenu.Items.Add(rmi1);     
            contextMenu.Items.Add(rmi2);    

Once the menu object has been initialized and populated with menu items, it is ready to be attached to the RadGridView. To do that, subscribe to the ContextMenuOpening event:

 
radGridView1.ContextMenuOpening += new ContextMenuOpeningEventHandler(radGridView1_ContextMenuOpening);  
 

In the handler of the ContextMenuOpening event, set the context menu to be displayed:

        void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)  
        {  
            e.ContextMenu = contextMenu;  
        } 

 

Comments

  • Sasmita , Jul 8, 2008

    Hi , I found this article very useful. i have a query. I have two grids and i am sharing the common context menu in both the grids. When i click on the Menu Item i need to know the grid ID that invoked the Context menu. Any kind of help is appreciated

  • Telerik Admin , Jul 9, 2008

    We will kindly ask you to use the support ticketing system (www.telerik.com/clientnet) for all support inquiries. Thanks.

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.