windowsforms-devexpress-dot-xtratreelist-dot-treelist-dot-appendnode-x28-system-dot-object-devexpress-dot-xtratreelist-dot-nodes-dot-treelistnode-x29.md
Adds a new TreeListNode containing the specified values to the XtraTreeList.
Namespace : DevExpress.XtraTreeList
Assembly : DevExpress.XtraTreeList.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
public virtual TreeListNode AppendNode(
object nodeData,
TreeListNode parentNode
)
Public Overridable Function AppendNode(
nodeData As Object,
parentNode As TreeListNode
) As TreeListNode
| Name | Type | Description |
|---|---|---|
| nodeData | Object |
An array of values or a DataRow object, used to initialize the created node’s cells.
| | parentNode | TreeListNode |
A parent node of the added one.
|
| Type | Description |
|---|---|
| TreeListNode |
A TreeListNode object representing the added node.
|
Use the AppendNode method to append a new node to the specified node’s child collection. Use the parentNode parameter to specify the parent node. To add a node at the root level, set the parentNode parameter to null.
The nodeData parameter specifies data for the columns of the node that is to be created. This parameter value can be an array of values or a DataRow object. The number and order of items in the array/DataRow object must match the number and order of Tree List columns.
Refer to the Nodes topic to learn more.
The following code shows how to manually populate a TreeList control with nodes in unbound mode.
To add nodes in unbound mode, utilize the TreeList.AppendNode method. Data that is passed to this method must match the TreeList columns. So, the TreeList columns are created before the nodes are created.
Note that calls to the methods used to create nodes are wrapped with the TreeList.BeginUnboundLoad and TreeList.EndUnboundLoad methods. This reduces the control’s updates to a minimum, and thus improves performance.
The following image displays the result.
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Nodes;
private void Form1_Load(object sender, EventArgs e) {
CreateColumns(treeList1);
CreateNodes(treeList1);
}
private void CreateColumns(TreeList tl) {
// Create three columns
tl.BeginUpdate();
TreeListColumn col1 = tl.Columns.Add();
col1.FieldName = "Customer";
col1.Caption = "Customer";
col1.VisibleIndex = 0;
TreeListColumn col2 = tl.Columns.Add();
col2.FieldName = "Location";
col2.Caption = "Location";
col2.VisibleIndex = 1;
TreeListColumn col3 = tl.Columns.Add();
col3.FieldName = "Phone";
col3.Caption = "Phone";
col3.VisibleIndex = 2;
tl.EndUpdate();
}
private void CreateNodes(TreeList tl) {
tl.BeginUnboundLoad();
// Create a root node
TreeListNode parentForRootNodes = null;
TreeListNode rootNode = tl.AppendNode(
new object[] { "Alfreds Futterkiste", "Germany, Obere Str. 57", "030-0074321" },
parentForRootNodes);
// Create a child of the rootNode
tl.AppendNode(new object[] { "Suyama, Michael", "Obere Str. 55", "030-0074263" }, rootNode);
// Create more nodes
// ...
tl.EndUnboundLoad();
}
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Columns
Imports DevExpress.XtraTreeList.Nodes
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateColumns(treeList1)
CreateNodes(treeList1)
End Sub
Private Sub CreateColumns(ByVal tl As TreeList)
' Create three columns
tl.BeginUpdate()
Dim col1 As TreeListColumn = tl.Columns.Add()
col1.FieldName = "Customer"
col1.Caption = "Customer"
col1.VisibleIndex = 0
Dim col2 As TreeListColumn = tl.Columns.Add()
col2.FieldName = "Location"
col2.Caption = "Location"
col2.VisibleIndex = 1
Dim col3 As TreeListColumn = tl.Columns.Add()
col3.FieldName = "Phone"
col3.Caption = "Phone"
col3.VisibleIndex = 2
tl.EndUpdate()
End Sub
Private Sub CreateNodes(ByVal tl As TreeList)
tl.BeginUnboundLoad()
' Create a root node
Dim parentForRootNodes As TreeListNode = Nothing
Dim rootNode As TreeListNode = tl.AppendNode(New Object() { "Alfreds Futterkiste", "Germany, Obere Str. 57", "030-0074321" }, parentForRootNodes)
' Create a child of the rootNode
tl.AppendNode(New Object() { "Suyama, Michael", "Obere Str. 55", "030-0074263" }, rootNode)
' Create more nodes
' ...
tl.EndUnboundLoad()
End Sub
The following code snippets (auto-collected from DevExpress Examples) contain references to the AppendNode(Object, TreeListNode) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
di = new DirectoryInfo(s);
node = treeList1.AppendNode(new object[] { s, di.Name, "Folder", null }, pNode);
node.StateImageIndex = 0;
winforms-treelist-create-file-manager-drag-drop-files-folders/CS/FileList/FileListHelper.cs#L99
di = new DirectoryInfo(s);
node = Tree.AppendNode(new object[] { s, di.Name, "Folder", null, di }, pNode);
node.StateImageIndex = 0;
drag-drop-grid-rows-to-treelist/CS/DragAndDropRows/Form1.cs#L80
parentID = (int)destNode["ID"];
TreeListNode node = treeList.AppendNode(new PersonEx(person, parentID).ToArray(), destIndex == -1000 ? destNode : null);
if(destIndex > -1) {
winforms-treelist-customize-node-menu/CS/Form1.cs#L31
private void bbAddChild_ItemClick(object sender, EventArgs e) {
TreeListNode newNode = treeList1.AppendNode(null, treeList1.FocusedNode);
newNode.SetValue(0, "New Node");
di = New DirectoryInfo(s)
node = treeList1.AppendNode(New Object() {s, di.Name, "Folder", Nothing}, pNode)
node.StateImageIndex = 0
winforms-treelist-create-file-manager-drag-drop-files-folders/VB/FileList/FileListHelper.vb#L81
di = New DirectoryInfo(s)
node = Tree.AppendNode(New Object() {s, di.Name, "Folder", Nothing, di}, pNode)
node.StateImageIndex = 0
drag-drop-grid-rows-to-treelist/VB/DragAndDropRows/Form1.vb#L76
If destNode IsNot Nothing Then parentID = CInt(destNode("ID"))
Dim node As TreeListNode = treeList.AppendNode(New PersonEx(person, parentID).ToArray(), If(destIndex = -1000, destNode, Nothing))
If destIndex > -1 Then
winforms-treelist-customize-node-menu/VB/Form1.vb#L33
Private Sub bbAddChild_ItemClick(ByVal sender As Object, ByVal e As EventArgs)
Dim newNode As TreeListNode = treeList1.AppendNode(Nothing, treeList1.FocusedNode)
newNode.SetValue(0, "New Node")
See Also