Back to Devexpress

TreeListNodeBase.Content Property

corelibraries-devexpress-dot-data-dot-treelist-dot-treelistnodebase.md

latest9.0 KB
Original Source

TreeListNodeBase.Content Property

Gets or sets the node’s content.

Namespace : DevExpress.Data.TreeList

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public virtual object Content { get; set; }
vb
Public Overridable Property Content As Object

Property Value

TypeDescription
Object

An object that specifies the node’s content.

|

Remarks

Nodes can be specified by objects of different types. The only requirement is that these data objects should have common fields (columns).

Example

This example shows how to manually create a tree (unbound mode). It is shown how to create nodes in XAML and code.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/wpf-treelist-create-unbound-tree

csharp
using System;
using System.Windows;
using DevExpress.Xpf.Grid;

namespace TreeListView_UnboundMode {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            BuildTree();
            treeListView1.ExpandAllNodes();
        }

        private void BuildTree() {
            TreeListNode rootNode = CreateRootNode(new ProjectObject() { Name = "Project: Stanton", Executor = "Nicholas Llams" });
            TreeListNode childNode = CreateChildNode(rootNode, new StageObject() { Name = "Information Gathering", Executor = "Ankie Galva" });
            CreateChildNode(childNode, new TaskObject() { Name = "Design", Executor = "Reardon Felton", State = "In progress" });
        }

        private TreeListNode CreateRootNode(object dataObject) {
            TreeListNode rootNode = new TreeListNode(dataObject);
            treeListView1.Nodes.Add(rootNode);
            return rootNode;
        }

        private TreeListNode CreateChildNode(TreeListNode parentNode, object dataObject) {
            TreeListNode childNode = new TreeListNode(dataObject);
            parentNode.Nodes.Add(childNode);
            return childNode;
        }
    }

    public class StageObject {
        public String Name { get; set; }
        public string Executor { get; set; }
    }

    public class ProjectObject {
        public String Name { get; set; }
        public string Executor { get; set; }
    }

    public class TaskObject {
        public String Name { get; set; }
        public string Executor { get; set; }
        public string State { get; set; }
    }
}
xaml
<Window x:Class="TreeListView_UnboundMode.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:local="clr-namespace:TreeListView_UnboundMode">
    <Grid>
        <dxg:GridControl Name="grid">
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="Name" />
                <dxg:GridColumn FieldName="Executor" />
                <dxg:GridColumn FieldName="State" />
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TreeListView Name="treeListView1" AutoWidth="True">
                    <dxg:TreeListView.Nodes>
                        <dxg:TreeListNode>
                            <dxg:TreeListNode.Content>
                                <local:ProjectObject Name="Project: Betaron" Executor="Destiny Tabisola" />
                            </dxg:TreeListNode.Content>
                            <dxg:TreeListNode.Nodes>
                                <dxg:TreeListNode>
                                    <dxg:TreeListNode.Content>
                                        <local:StageObject Name="Development" Executor="Kairra Hogg" />
                                    </dxg:TreeListNode.Content>
                                    <dxg:TreeListNode.Nodes>
                                        <dxg:TreeListNode>
                                            <dxg:TreeListNode.Content>
                                                <local:TaskObject Name="Coding" Executor="Sabato Durley" State="Not Started" />
                                            </dxg:TreeListNode.Content>
                                        </dxg:TreeListNode>
                                    </dxg:TreeListNode.Nodes>
                                </dxg:TreeListNode>
                            </dxg:TreeListNode.Nodes>
                        </dxg:TreeListNode>
                    </dxg:TreeListView.Nodes>
                </dxg:TreeListView>
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</Window>
vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports DevExpress.Xpf.Grid

Namespace TreeListView_UnboundMode
    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
            BuildTree()
            treeListView1.ExpandAllNodes()
        End Sub

        Private Sub BuildTree()
            Dim rootNode As TreeListNode = CreateRootNode(New ProjectObject() With {.Name = "Project: Stanton", .Executor = "Nicholas Llams"})
            Dim childNode As TreeListNode = CreateChildNode(rootNode, New StageObject() With {.Name = "Information Gathering", .Executor = "Ankie Galva"})
            CreateChildNode(childNode, New TaskObject() With {.Name = "Design", .Executor = "Reardon Felton", .State = "In progress"})
        End Sub

        Private Function CreateRootNode(ByVal dataObject As Object) As TreeListNode
            Dim rootNode As New TreeListNode(dataObject)
            treeListView1.Nodes.Add(rootNode)
            Return rootNode
        End Function

        Private Function CreateChildNode(ByVal parentNode As TreeListNode, ByVal dataObject As Object) As TreeListNode
            Dim childNode As New TreeListNode(dataObject)
            parentNode.Nodes.Add(childNode)
            Return childNode
        End Function
    End Class

    Public Class StageObject
        Private privateName As String
        Public Property Name() As String
            Get
                Return privateName
            End Get
            Set(ByVal value As String)
                privateName = value
            End Set
        End Property
        Private privateExecutor As String
        Public Property Executor() As String
            Get
                Return privateExecutor
            End Get
            Set(ByVal value As String)
                privateExecutor = value
            End Set
        End Property
    End Class

    Public Class ProjectObject
        Private privateName As String
        Public Property Name() As String
            Get
                Return privateName
            End Get
            Set(ByVal value As String)
                privateName = value
            End Set
        End Property
        Private privateExecutor As String
        Public Property Executor() As String
            Get
                Return privateExecutor
            End Get
            Set(ByVal value As String)
                privateExecutor = value
            End Set
        End Property
    End Class

    Public Class TaskObject
        Private privateName As String
        Public Property Name() As String
            Get
                Return privateName
            End Get
            Set(ByVal value As String)
                privateName = value
            End Set
        End Property
        Private privateExecutor As String
        Public Property Executor() As String
            Get
                Return privateExecutor
            End Get
            Set(ByVal value As String)
                privateExecutor = value
            End Set
        End Property
        Private privateState As String
        Public Property State() As String
            Get
                Return privateState
            End Get
            Set(ByVal value As String)
                privateState = value
            End Set
        End Property
    End Class
End Namespace

See Also

TreeListNodeBase Class

TreeListNodeBase Members

DevExpress.Data.TreeList Namespace