一、控件设定:
1.页面添加ContextMenuStrip控件;
2.ContextMenuStrip添加菜单项;
3.gridControl找到ContextMenuStrip属性,设置成刚添加ContextMenuStrip;
二、代码实现:
private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e) { try { int intselect = gridView1.SelectedRowsCount; MenuItemEdit.Enabled = false; MenuItemDelete.Enabled = false; if (intselect == 1) { MenuItemEdit.Enabled = true; MenuItemDelete.Enabled = true; } else if (intselect > 1) { MenuItemEdit.Enabled = false; MenuItemDelete.Enabled = false; } } catch (Exception ex) { app.Alert(ex.Message); } } private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { try { if ((e.ClickedItem).Name == "MenuItemEdit") { OpenUpdateWin(); } else if ((e.ClickedItem).Name == "MenuItemDelete") { DoDelete(); } } catch (Exception ex) { app.Alert(ex.Message); } }
原文引用:https://blog.csdn.net/jiankunking/article/details/46316973