|
Queries |
Solution |
|
1. To open all parent nodes using below code. But, it’s not working.
TreeNodeAdv pNode = AccountsTree.ActiveNode.Parent;
while(pNode != null)
{
pNode.Expand();
pNode.Expanded = true;
pNode = pNode.Parent;
}
AccountsTree.Refresh(); |
From your update, we could understood that you want to expand all parent node . You can achieve it using ExpandAll() method.
Refer below code.
private void TreeViewAdv1_AfterSelect(object sender, EventArgs e)
{
if (treeViewAdv1.ActiveNode != null)
{
TreeNodeAdv root = treeViewAdv1.ActiveNode.Parent;
while (root != null)
{
root.ExpandAll();
root.Expanded = true;
root = root.Parent;
}
treeViewAdv1.Refresh();
}
} |
|
2. make the previously selected child visible/selected node |
If you want to show the previously selected node, you need to use BringToView() method. Refer the below link.
Code:
private void TreeViewAdv1_AfterSelect(object sender, EventArgs e)
{
if (treeViewAdv1.ActiveNode != null)
{
TreeNodeAdv root = treeViewAdv1.ActiveNode.Parent;
root.BringIntoView();
while (root != null)
{
root.ExpandAll();
root.Expanded = true;
root = root.Parent;
}
treeViewAdv1.Refresh();
}
} |