• 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

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.

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