如何将菜单项添加到默认右键单击devexpress treelist

时间:2010-12-03 20:19:13

标签: vb.net devexpress

我有一个DevExpress(版本9.2)TreeList,默认情况下会显示一个菜单,其中包含排序升序/降序,列选择器,以及右键单击树标题时的最佳拟合。

如何向此默认菜单添加更多选项?

2 个答案:

答案 0 :(得分:1)

    void treeList1_PopupMenuShowing(object sender, DevExpress.XtraTreeList.PopupMenuShowingEventArgs e)
    {
        DXMenuItem item = new DXMenuItem("New menu item");
        e.Menu.Items.Add(item);


    }

或者在表单加载事件处理程序中添加菜单项。根据需要添加菜单点击处理程序。

答案 1 :(得分:1)

要添加到默认菜单,您需要使用ShowTreeListMenu动作侦听器并在其中添加行。

  Private Sub treeCompany_ShowTreeListMenu(ByVal sender As System.Object, ByVal e As DevExpress.XtraTreeList.TreeListMenuEventArgs) Handles treeCompany.ShowTreeListMenu
       ' add the ability to expand the nodes in the tree
        e.Menu.Items.Add(New DevExpress.Utils.Menu.DXMenuItem("Expand All Nodes", AddressOf ExpandNode))
       ' make the last item added begin the group so you have a divider
        e.Menu.Items(e.Menu.Items.Count - 1).BeginGroup = True
       ' add the ability to collapse the nodes in the tree
        e.Menu.Items.Add(New DevExpress.Utils.Menu.DXMenuItem("Collapse All Nodes", AddressOf CollapseAll))
  End Sub

第一次添加调用函数ExpandNode(),第二次调用调用CollapseAll()