expand all parent node

S

Sinan Alkan

when using a Treeview control, is it possible to expand all parent nodes for
a specific node ?
 
M

Martin Honnen

Sinan said:
when using a Treeview control, is it possible to expand all parent nodes for
a specific node ?

Is there more one parent node in a tree model? I don't think so. Or did
you want to say "ancestor nodes" instead of "parent nodes"?
 
M

Martin Honnen

Sinan said:
I mean all ancestor nodes.

Then do
TreeNode parentNode = yourTreeNodeInstance.Parent;
while (parentNode != null)
{
parentNode.Expand();
parentNode = parentNode.Parent;
}
 
C

comphilip

It is possible;

private void ExpandParentNodes(TreeNode node){
TreeNode parent = node.ParentNode;
while(parent != null){
parent.Expand();
parent = parent.parentNode;
}
}
 
J

Jeff Johnson

when using a Treeview control, is it possible to expand all parent nodes
for a specific node ?

Just make the node visible. All its ancestors will automatically be
expanded. After all, how can you see a child node without seeing the parent
chain?
 
J

Jeff Johnson

Just make the node visible. All its ancestors will automatically be
expanded. After all, how can you see a child node without seeing the
parent chain?

Hmmm, I just noticed this was cross-posted to the ASP.NET group. It's
helpful if you mention that you're doing this on a Web form if you're going
to cross-post to a general group like C#, because some folks (like me!) will
assume you're talking about a native Windows tree view control, and not a
Web control. Now I'm not positive that my answer will help you, because I'm
not a Web programmer and I don't know if that tree view behaves the same
way, although I'd think it would in this case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top