下面的示例演示了如何把一个自定义菜单项添加到标准的上下文菜单中,并且为此菜单项订阅了单击事件。 TreeList.ShowTreeListMenu 事件被接管,以便于把 Clear All 菜单项添加到 汇总脚注菜单 中。 单击此菜单项则取消所有树状列表列的汇总计算。

下面的插图展示了运行结果。

C#CopyCode image复制代码
using DevExpress.Utils.Menu;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
//...
private void treeList1_ShowTreeListMenu(object sender, DevExpress.XtraTreeList.TreeListMenuEventArgs e) {
   TreeListHitInfo hitInfo = treeList1.CalcHitInfo(e.Point);
   if(hitInfo.HitInfoType == HitInfoType.SummaryFooter)
      e.Menu.Items.Add(new DXMenuItem("Clear All", new EventHandler(this.clearAllMenuItemClick)));
}

private void clearAllMenuItemClick(object sender, EventArgs e) {
   foreach (TreeListColumn column in treeList1.Columns) 
      column.SummaryFooter = SummaryItemType.None;
}
Visual BasicCopyCode image复制代码
Imports DevExpress.Utils.Menu
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Columns
'...
Private Sub TreeList1_ShowTreeListMenu(ByVal sender As Object, 
ByVal e As DevExpress.XtraTreeList.TreeListMenuEventArgs) 
Handles TreeList1.ShowTreeListMenu
   Dim HitInfo As TreeListHitInfo = TreeList1.CalcHitInfo(e.Point)
   If HitInfo.HitInfoType = HitInfoType.SummaryFooter Then
      e.Menu.Items.Add(New DXMenuItem("Clear All", AddressOf Me.clearAllMenuItemClick))
   End If
End Sub

Private Sub clearAllMenuItemClick(ByVal sender As Object, ByVal e As EventArgs)
   Dim Column As TreeListColumn
   For Each Column In TreeList1.Columns
      Column.SummaryFooter = SummaryItemType.None
   Next
End Sub