禁用和移除标准菜单中的特定菜单项
当任何 标准上下文菜单 被调用时,TreeList.ShowTreeListMenu 事件都发生。 此事件允许通过 Menu 参数访问当前菜单,然后修改它。
例如,易于阻止显示菜单、或者禁用并/或移除某些菜单项。
示例
下面的示例代码接管了 TreeList.ShowTreeListMenu 事件,以便于实现下述两个目的。
- 禁用“Department”列的汇总脚注的上下文菜单。
- 移除列标头的上下文菜单中的“Runtime columns customization”菜单项。
C# | 复制代码 |
---|---|
using DevExpress.XtraTreeList; private void treeList1_ShowTreeListMenu(object sender, TreeListMenuEventArgs e) { TreeListHitInfo hitInfo = treeList1.CalcHitInfo(e.Point); // prohibiting summary footer menu for the "Department" column if (hitInfo.HitInfoType == HitInfoType.SummaryFooter && hitInfo.Column.Caption == "Department") e.Allow = false; // removing the "Runtime columns customization" item of the column header menu if (hitInfo.HitInfoType == HitInfoType.Column) e.Menu.Items.RemoveAt(3); } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraTreeList Private Sub TreeList1_ShowTreeListMenu(ByVal sender As Object, _ ByVal e As TreeListMenuEventArgs) Handles TreeList1.ShowTreeListMenu Dim HitInfo As TreeListHitInfo = TreeList1.CalcHitInfo(e.Point) ' prohibiting summary footer menu for the "Department" column If HitInfo.HitInfoType = HitInfoType.SummaryFooter _ And HitInfo.Column.Caption = "Department" Then e.Allow = False End If ' removing the "Runtime columns customization" item of the column header menu If HitInfo.HitInfoType = HitInfoType.Column Then e.Menu.Items.RemoveAt(3) End If End Sub |