How do you insert a child node in a TreeView Control in WPF C#?
I have a TreeView control that I have created in XAML in a WPF program using C#.
After adding a couple nodes at the root level, I have written code that loops through the tree structure like so:
ItemCollection items = treeView1.Items;
foreach (TreeViewItem n in items)
{
...
}
Once I find the place in this loop where I want to include a child node, how do I go about inserting a child?
How do you insert a child node in a TreeView Control in WPF C#?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


CrishRank #1,487 · 1.1K reputationPosted May 14, 2010, 9:49 PM EDT
please go through below link
http://www.c-sharpcorner.com/UploadFile/mahesh/WPFTreeView08202008231544PM/WPFTreeView.aspx
Also try,
var items = treeView1.Items; var item = new TreeViewItem() { Header = "Interesting" }; items.Add(item); var subitem = new TreeViewItem() {Header = "Sub Item"}; foreach (TreeViewItem n in items) { if (n.Header == "Interesting") (n as TreeViewItem).Items.Add(subitem); } Don't forget to Mark Do you like this Answer that solved your problem!