Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Collapse]Tree List
   [Expand]Product Information
   [Collapse]Feature Center
    [Expand]Data Binding
    [Expand]Nodes
    [Expand]Data Editing
    [Expand]Data Representation
    [Expand]Sorting
    [Expand]Filtering
    [Expand]Summaries
    [Expand]Appearances and Look And Feel
    [Expand]Focus, Selection and Navigation
     Formatting Cell Values
    [Collapse]Miscellaneous
     [Collapse]Context Menus
       Add Custom Menu Items to the Standard Menus
       Change the Behavior of the Standard Menu Items
       Control the Availability of the Standard Context Menus to End-Users
       Custom Menus
       Customize the Standard Context Menus
       Disable and Remove Particular Items in the Standard Menus
       Standard Context Menus
     [Expand]Export and Import Data
     [Expand]Print XtraTreeList
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End User Capabilities
   [Expand]Member Tables
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Custom Menus

The Tree List control supports context menus for column headers, group summary footers and the total summary footer. However, it's possible to implement custom menus for any other Tree List element.

Expanded Custom Menus

You can create a custom context menu and then display it when an end-user right-clicks the required Tree List element. To show the custom menu, handle the control's MouseDown event. Since this event fires when any Tree List element is clicked, you need to identify the Tree List element that has been clicked. To do this, call the TreeList.CalcHitInfo method within the MouseDown event handler.

The TreeList.CalcHitInfo method takes a point, relative to the Tree List's top-left corner, as a parameter. The method's result is a TreeListHitInfo object identifying the Tree List element located at the specified point.

Expanded Example

The following example demonstrates how to create a custom menu, and show it when a node indicator cell is clicked. The menu will contain the "Delete Node" command, allowing an end-user to delete nodes. The result is shown below:

To show the custom menu, the MouseDown event is handled. When this event fires, the TreeList.CalcHitInfo method is called to identify the Tree List element clicked. In the case of clicking a node indicator cell, the custom menu is created and displayed.

An end-user can select the "Delete Node" command within the menu, or close the menu by pressing ESC. If the "Delete Node" command is selected, an event handler (the deleteNodeMenuItemClick method), assigned to the menu item's Click event, is called. In this event handler, the clicked node is deleted.

To implement the custom menu in this example, the DevExpress.XtraTreeList.Menu.TreeListMenu class is used. This class represents the ancestor for the Tree List standard context menus. You can alternatively use the PopupMenu class, which provides design-time customization capabilities.

How would you rate this topic?​​​​​​​