如何在 devexpress 上保留默认列 header 弹出菜单?
How to keep the default column header popup menu on devexpress?
我在网格内容上添加了右键单击弹出菜单。当我右键单击网格 header 时也会显示此弹出窗口,但是,我想保留默认列 header 弹出菜单。
我的右键菜单代码是这样的:
protected override void RightClickMenu()
{
this.rightClickContextMenu = new ContextMenu();
this.rightClickContextMenu.MenuItems.Add("MY CLASSES", new System.EventHandler(myclasses_Click));
this.rightClickContextMenu.MenuItems.Add("MY BOOK LISTS", new System.EventHandler(booklists_Click));
this.gridView.PopupMenuShowing += gridView_PopupMenuShowing;
}
有人知道我应该在我的代码中添加什么吗?
如果不了解这种情况的所有方面,就很难提出建议。您应该 report this issue 直接联系 DevExpress 支持团队并提供可重现问题的示例项目。我相信他们的人可以使用您的示例诊断错误并修复它,或者使用 GridControl 上的 ContextMenu 为您指明正确的方向。
相关支持文章:Both ContextMenu and grid menu are shown simultaneously
您可以使用GridView.CalcHitInfo
方法来确定单击鼠标右键的位置。如果它是在 header 列上单击的,那么您必须将 GridControl.ContextMenu
属性 设置为 null
。
这是示例:
protected override void RightClickMenu()
{
this.rightClickContextMenu = new ContextMenu();
this.rightClickContextMenu.MenuItems.Add("MY CLASSES", new System.EventHandler(myclasses_Click));
this.rightClickContextMenu.MenuItems.Add("MY BOOK LISTS", new System.EventHandler(booklists_Click));
this.gridView.PopupMenuShowing += gridView_PopupMenuShowing;
this.gridView.MouseDown += gridView_MouseDown;
}
private void gridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right)
return;
var hitInfo = this.gridView.CalcHitInfo(e.Location);
if (!hitInfo.InColumn)
this.gridView.GridControl.ContextMenu = this.rightClickContextMenu;
else
this.gridView.GridControl.ContextMenu = null;
}
我在网格内容上添加了右键单击弹出菜单。当我右键单击网格 header 时也会显示此弹出窗口,但是,我想保留默认列 header 弹出菜单。
我的右键菜单代码是这样的:
protected override void RightClickMenu()
{
this.rightClickContextMenu = new ContextMenu();
this.rightClickContextMenu.MenuItems.Add("MY CLASSES", new System.EventHandler(myclasses_Click));
this.rightClickContextMenu.MenuItems.Add("MY BOOK LISTS", new System.EventHandler(booklists_Click));
this.gridView.PopupMenuShowing += gridView_PopupMenuShowing;
}
有人知道我应该在我的代码中添加什么吗?
如果不了解这种情况的所有方面,就很难提出建议。您应该 report this issue 直接联系 DevExpress 支持团队并提供可重现问题的示例项目。我相信他们的人可以使用您的示例诊断错误并修复它,或者使用 GridControl 上的 ContextMenu 为您指明正确的方向。
相关支持文章:Both ContextMenu and grid menu are shown simultaneously
您可以使用GridView.CalcHitInfo
方法来确定单击鼠标右键的位置。如果它是在 header 列上单击的,那么您必须将 GridControl.ContextMenu
属性 设置为 null
。
这是示例:
protected override void RightClickMenu()
{
this.rightClickContextMenu = new ContextMenu();
this.rightClickContextMenu.MenuItems.Add("MY CLASSES", new System.EventHandler(myclasses_Click));
this.rightClickContextMenu.MenuItems.Add("MY BOOK LISTS", new System.EventHandler(booklists_Click));
this.gridView.PopupMenuShowing += gridView_PopupMenuShowing;
this.gridView.MouseDown += gridView_MouseDown;
}
private void gridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right)
return;
var hitInfo = this.gridView.CalcHitInfo(e.Location);
if (!hitInfo.InColumn)
this.gridView.GridControl.ContextMenu = this.rightClickContextMenu;
else
this.gridView.GridControl.ContextMenu = null;
}