TreeView control....does a child node have children?

When I select a node..........how can I determine programmatically if the node has children?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
Hans LangerCommented:
Hi, Try this code,

this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
            
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
      if (e.Node.Nodes.Count > 0)
            MessageBox.Show("This Node Have " + e.Node.Nodes.Count.ToString() + " Nodes");
      else
            MessageBox.Show("This Node Have Not ChildNodes");
}

GL
0
 
Tom KnowltonWeb developerAuthor Commented:
I guess just a COUNT of how many children would be best.....and if the COUNT is > 0 I can make a decision based on that.
0
 
TertioptusCommented:
try this, say if your TreeView control name is treeView1, and it has at least one node, then this line of code should work as is.  Of course you can modify it your on configuration.:

treeView1.Nodes[0].Nodes.Count;



Basically you have to access the collection of nodes with a single node: i.e.  
TreeNode objNode = new TreeNode;
// population code
objNode.Nodes.Count
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Tom KnowltonWeb developerAuthor Commented:
Expert GERENTE:

Something about your name kept tickling the back of my mind.

"GERENTE" means "Manager" in Portuguese!  So are you a manager?

I spent a few years down in Sao Paulo, Brazil.

Mystery solved for my tireless subconscience.

:)

Tom
0
 
Hans LangerCommented:
GERENTE means "Manager" in spanish too,
Im Engineer, not manager, and I live in Chile (South America).
;)
0
 
Tom KnowltonWeb developerAuthor Commented:
Cool!

or rather,

Que Otimo!

Tom  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.