Solved

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

Posted on 2004-10-08
6
266 Views
Last Modified: 2010-04-15
When I select a node..........how can I determine programmatically if the node has children?
0
Comment
Question by:knowlton
  • 3
  • 2
6 Comments
 
LVL 5

Author Comment

by:knowlton
ID: 12261203
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
 
LVL 5

Assisted Solution

by:Tertioptus
Tertioptus earned 250 total points
ID: 12261724
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
 
LVL 10

Accepted Solution

by:
Hans Langer earned 250 total points
ID: 12273723
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 5

Author Comment

by:knowlton
ID: 12346429
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
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12346660
GERENTE means "Manager" in spanish too,
Im Engineer, not manager, and I live in Chile (South America).
;)
0
 
LVL 5

Author Comment

by:knowlton
ID: 12346690
Cool!

or rather,

Que Otimo!

Tom  :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
Error on link 14 46
open System.IO.Compression.ZipArchiveEntry as ZipFile without storing to file 2 56
List<PaisEntity> - show some 1 22
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now