Is there a way to automatically expand all nodes from a treeview in WPF? I searched and didn\'t even find an expand function in the treeview property.
Thanks
This is what I use:
private void ExpandAllNodes(TreeViewItem rootItem)
{
foreach (object item in rootItem.Items)
{
TreeViewItem treeItem = (TreeViewItem)item;
if (treeItem != null)
{
ExpandAllNodes(treeItem);
treeItem.IsExpanded = true;
}
}
}
In order for it to work you must call this method in a foreach loop for the root node:
// this loop expands all nodes
foreach (object item in myTreeView.Items)
{
TreeViewItem treeItem = (TreeViewItem)item;
if (treeItem != null)
{
ExpandAllNodes(treeItem);
treeItem.IsExpanded = true;
}
}