|
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; |
| } |
Please
Sign In
to rate this article.