[Expand]General Information
[Expand]WinForms Controls
[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]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
  [Expand]Application Solution Components
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]UI Construction
  [Expand]Controllers and Actions
  [Expand]Data Manipulation and Business Logic
  [Expand]Security System
  [Expand]System Module
  [Collapse]Extra Modules
   [Expand]Audit Trail Module
    Business Class Library Customization Module
    Chart Module
    Clone Object Module
   [Expand]Conditional Appearance Module
   [Expand]Dashboards Module
    File Attachments Module
    HTML Property Editor Module
    Localization Module
   [Expand]Notifications Module
    KPI Module
   [Expand]Maps Module
   [Expand]Pivot Chart Module
    Pivot Grid Module
   [Expand]Reports V2 Module
   [Expand]Office Module
   [Expand]Scheduler Module
    Script Recorder Module
   [Expand]State Machine Module
   [Collapse]TreeList Editors Module
     TreeList Editors Module Overview
     Display a Tree List using the ITreeNode Interface
     Display a Tree List using the HCategory Class
     Node Images in a Tree List
     Categorized List
   [Expand]Validation Module
    View Variants Module
   [Expand]Workflow Module
  [Expand]Debugging, Testing and Error Handling
  [Expand]Application Life Cycle
 [Expand]Design-Time Features
 [Expand]Task-Based Help
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Display a Tree List using the HCategory Class

To display data in a tree-like structure, the ITreeNode interface should be implemented in the appropriate business classes. The objects that support this interface are displayed via the ASPxTreeList and TreeList controls from the ASPxTreeList and XtraTreeList libraries. This is provided by the TreeList Editors module. To learn more about the ITreeNode interface and the List Editor supplied for it with the TreeList Editors module, refer to the TreeList Editors Module Overview topic. This topic demonstrates how to use the ready-to-use HCategory class that implements the ITreeNode interface. This class is supplied with the Business Class Library, so you can easily use it instead of implementing the ITreeNode class from scratch.


A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1125.

The HCategory class is implemented so that its Parent and Children properties can reference objects of the HCategory type only.

To add the Business Class Library's HCategory class to your business model, use the Designer of the required module (application module or Windows Forms module). First, check that the DevExpress.Persistent.BaseImpl.v19.1.dll assembly is referenced in this module. Then, invoke the Module Designer. In the Exported Types section, select the Referenced Assemblies | DevExpress.Persistent.BaseImpl | HCategory item. Mark it bold by pressing the SPACEBAR. Do not forget to rebuild the solution after making changed in a Designer.

To add the HCategory class to the navigation control, invoke the Model Editor for the current module. Add the HCategory node to the NavigationItems node (see Add an Item to the Navigation Control).

To display the HCategory object as a tree, add the TreeList Editors module to the application. Since this module supplies Windows Forms specific instruments only, add it to the Windows Forms application project. For this purpose, invoke the Application Designer and drag the module from the Toolbox to the Modules section.

Run the Windows Forms application. Click the HCategory item in the navigation control. Then, create HCategory objects via the New Action. You will see that these objects will be displayed as a tree by the HCategory List View:

You can also display a collection of items for each HCategory node to the right of the tree list. For details, refer to the Categorized List topic.

If you need to extend the HCategory class, inherit from it (see Inherit from the Business Class Library Class (XPO)).

If you need to implement the ITreeNode interface from scratch, refer to the Display a Tree List using the ITreeNode Interface topic for details.

To see the HCategory class implementation, refer to the %PROGRAMFILES(x86)%\DevExpress 19.1\Components\Sources\DevExpress.Persistent\DevExpress.Persistent.BaseImpl folder, where you can find the HCategory.cs file.


The TreeListEditor and CategorizedListEditor cannot properly display a tree if the List View's object type is a descendant of the base type, which implements the ITreeNode interface, and the hierarchy contains base type objects.

For example, suppose you have a tree formed by HCategory descendant objects, which have child HCategory objects. If you try to invoke a List View for an HCategory descendant type, the TreeListEditor and CategorizedListEditor will not be able to correctly display this structure. To correctly display such a tree, invoke a List View for the base type, in this instance - HCategory.

Expanded See Also

Is this topic helpful?​​​​​​​