Example E712
Visible to All Users

WinForms Data Grid - How to display a context menu for rows

This example shows how to display a custom context menu when the user right-clicks on a data row.

Files to Review

Documentation

See Also

Example Code

FormGridMenu.cs(vb)
C#
using DevExpress.Utils.Menu; using DevExpress.XtraBars; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; namespace RowsPopupMenu { public partial class FormGridMenu : DevExpress.XtraEditors.XtraForm { public FormGridMenu() { InitializeComponent(); } private void Form1_Load(object sender, System.EventArgs e) { new DevExpress.XtraGrid.Design.XViewsPrinting(gridControl1); } private void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) { if (e.MenuType == GridMenuType.Row) { popupMenu_Row.Tag = e.HitInfo; e.ShowCustomMenu(popupMenu_Row); } } GridHitInfo GetHitInfo(BarItemLink link) { PopupMenu menu = link.LinkedObject as PopupMenu; return menu.Tag as GridHitInfo; } private void barButtonItem_Edit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { GridHitInfo info = GetHitInfo(e.Link); info?.View.ShowEditor(); } private void barButtonItem_Delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { GridHitInfo info = GetHitInfo(e.Link); info.View.DeleteRow(info.View.FocusedRowHandle); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.