Newbie: 2 questions associated with treeview/treenode

J

Jeff

IDE = Visual Studio 2003 .Net
OS = XP Pro
**********************************
treeviews:
Below is an illustration of a treeview with som data...
? Root
? .Net
? C#

When I run treeView1.Nodes.Count against the treeview example above I get
the value 1. But I thought I should get 3

This example:
? Root
? .Net
? C#
? ASP.NET
Here treeView1.Nodes.Count = 2

Is it so that treeView1.Nodes.Count only returns the number of nodes at root
level?.. I think that is stranged!

Any tips about this??

**********************************
About the TreeNodeCollection.Contains Method:

In the help file about this method I read this : "Determines whether the
specified tree node is a member of the collection."

From my understanding of this method the parameter to this method is a
treenode. But what if I only have the text value for the treenode and not
its name, then i cannot use the Contains method... Am I right here, or is
there a way I can search a treeview for a node without knowing its name???

Any tips about this??
*************************************************
Regards

Jeff
 
A

adnan boz

Hi,
Count is the property of Nodes and therefore it will return only the current
count of nodes.
I don't know which treeview you use, but in general you have to use a code
something like this:

treeView1.Nodes[0].Nodes.Count; //should give you the count of the first
subnode nodes.
treeView1.Nodes[0].Nodes[5].Nodes.Count; //should give you the count of the
first subnodes 5th subnode nodes.

Because it's a treeview, every Node has a Nodes collection.

Likewise, if the treeview control doesn't support a property like "count of
all nodes",
you have to loop trough all items and count it yourself.
Or you could store the added items count on a public variable (depends on
your needs),
increase it on item add and decrease it on item remove (if any).

Good Luck
Adnan
 

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

Top