Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

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

When I select a node..........how can I determine programmatically if the node has children?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 3
  • 2
2 Solutions
 
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now