469,610 Members | 1,920 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Treeview Checked Count Problem

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

Mar 4 '07 #1
2 2760
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?...f-c9d54e1a8d9e

I hope this helps something,

Cor

"Norton Who" <No********@gmail.comschreef in bericht
news:11**********************@c51g2000cwc.googlegr oups.com...
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

Mar 4 '07 #2
Norton Who wrote:
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.
Mar 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jeroen Ceuppens | last post: by
3 posts views Thread by feel | last post: by
2 posts views Thread by Srinivasa Raghavan | last post: by
1 post views Thread by Srinivasa Raghavan | last post: by
reply views Thread by Brian Keating | last post: by
1 post views Thread by Christian Rühl | last post: by
1 post views Thread by Christian Rühl | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.