While using DevExpress GridView if you need to show a context menu when the user right clicks on the GridView then you have to handle theShowGridMenu event of the GridView.
For example, let’s say I have a GridView as grdvCustomer and I want to show two buttons while the user right clicks on a row of the GridView. Then first of all I have to check the DevExpress.XtraGrid.Views.Grid.GridMenuTypemust be “Row”. Then using the ShowGridMenu event I can show the Context Menu.
You have to import these two namespaces
Here is the code to implement the event:-
private void grdvCustomer_ShowGridMenu(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs e)
// Check whether a row is right-clicked.
if (e.MenuType == GridMenuType.Row)
// Delete existing menu items, if any.
DXMenuItem menuItemUp = new DXMenuItem("Move Up", new EventHandler(MoveUp));
DXMenuItem menuItemDown = new DXMenuItem("Move Down", new EventHandler(MoveDown));
In the above lines of code you can see two new EventHandlers are created whose target methods are MoveUp and MoveDown. You can define your methods with these names and implement your code there.