TreeNode parentNode = new TreeNode("Parent Node"); TreeNode childNode1 = new TreeNode("Child Node 1"); TreeNode childNode2 = new TreeNode("Child Node 2"); parentNode.Nodes.Add(childNode1); // Adding childNode1 to parentNode parentNode.Nodes.Add(childNode2); // Adding childNode2 to parentNode
TreeViewItem parentNode = new TreeViewItem { Header = "Parent Node" }; TreeViewItem childNode1 = new TreeViewItem { Header = "Child Node 1" }; TreeViewItem childNode2 = new TreeViewItem { Header = "Child Node 2" }; parentNode.Items.Add(childNode1); // Adding childNode1 to parentNode parentNode.Items.Add(childNode2); // Adding childNode2 to parentNodeBoth examples use the AddChild method to add child nodes to the parent node. The package library could be System.Windows.Forms or System.Windows.Controls depending on whether the application uses WinForms or WPF for UI.