Treeview Checked Count Problem

N

Norton Who

Hi,

Could I please ask if anyone could help me solve this problem in
VS2003:

I'm trying to count all the nodes that have a Checked state however
this doesn't seem to be working for me.

So here is the code:

Dim prCount As Integer 'parent checked count
Dim chCount As Integer 'child checked count
Dim tn As New TreeNode
For Each tn In Me.TreeView_db.Nodes
If tn.Tag = "Column" Then
If tn.Checked = True Then
chCount = chCount + 1
End If
ElseIf tn.Tag = "Table" Then
If tn.Checked = True Then
prCount = prCount + 1
End If
End If
Next tn

This is not giving me the right count, actually it's giving me zero
always.

Thank You,

Norton Who
 
C

Cor Ligthert [MVP]

Norton,

I thought that this newsgroup was filled with recursive samples about this
problem. I saw it is not so it is a nice sample to make for our newsgroup
one of these days. (Not today anymore for that it is to late now.

Basicly you have to do it recursive. Create a method that you use to call
itself as long as that not everything is done. A treeview exist from nodes
which hold nodes etc etc.

(I give you a sample on our website from recursive, be aware this is not
about a treeview that I could not find for VB.Net).

http://www.vb-tips.com/dbpages.aspx?ID=8315dbfe-d51c-4189-a18f-c9d54e1a8d9e

I hope this helps something,

Cor
 
P

Phill W.

Norton said:
I'm trying to count all the nodes that have a Checked state however
this doesn't seem to be working for me.

So here is the code: .. . .
For Each tn In Me.TreeView_db.Nodes

[tree].Nodes no longer contains all the Nodes in the tree (unlike VB6).

It /only/ contains the Nodes at the /root/ level.

Every Node has its own Nodes collection, so you need to go Recursive to
retrieve them all.

HTH,
Phill W.
 

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