以编程方式在 gridControl / gridView1 (C# / DevExpress) 上自定义右键单击菜单

Right click menu customise on gridControl / gridView1 (C# / DevExpress) Programatically

如何自定义gridcontrol的右键菜单?我尝试将导出选项放在菜单上。我尝试在 Grid Design 中搜索仍然无法找到它。尝试 google 这几个星期。需要师傅指导。 TQ

只有一个控件名称 contextmenu 您可以从代码或设计器中添加它,然后添加一些事件。你可以 google 自己或 Adding a right click menu to an item

您可以处理 GridView 的 PopupMenuShowing event 并自定义内置的 Grid 菜单:

private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
    if (e.MenuType != DevExpress.XtraGrid.Views.Grid.GridMenuType.Column)
        return;

    DXMenuItem restoreItem = new DXMenuItem() { Caption = "Restore Layout" };
    restoreItem.Click += restoreItem_Click;

    e.Menu.Items.Add(restoreItem);
}

private void restoreItem_Click(object sender, EventArgs e)
{
    MessageBox.Show("Restoring layout...");
}

另请参阅:How to: Implement Custom Menu in XtraGrid Control