How to add a menu item to the default right-click on the devexpress treelist
I have a DevExpress (version 9.2) TreeList that by default displays a menu containing sort ascending/descending, column chooser, and bes开发者_C百科t fit when you right-click on the header of the tree.
How would I add more choices to this default menu?
void treeList1_PopupMenuShowing(object sender, DevExpress.XtraTreeList.PopupMenuShowingEventArgs e)
{
DXMenuItem item = new DXMenuItem("New menu item");
e.Menu.Items.Add(item);
}
Or do the menu item add in the form load event handler. Add a menu click handler as needed.
To add to the default menu you need to use the ShowTreeListMenu action listener and add the rows in there.
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
The first addition calls the function ExpandNode()
and the second calls CollapseAll()
.
精彩评论