Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Challanging Tree View Problem

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Hey guys,

Ok, I know that this is actually an asp.net question, and that i'm developing in vb.net, but I figured if one of you have done something like this in c# (eitehr web or desktop), it might point me in the right direction.

I have a page with an expanded treeview. The plusses are removed, and checkboxes are viewable. This is an admin screen for setting up permissions. What I want to do is look through the treeview when a button is clicked, gather all the nodes that are checked, and save them. However, when I try and cycle through the TreeView1.Nodes() collection, I'm always getting a count of 1, even though there are over 200 nodes in the treeview!

Any thoughts or tips on how I can get this to work?

Thanks,
:)

jack
 
You will have to recurse through all the child nodes to get your count. Your Treeview1.Nodes().Count is just returning you the count of the top-level nodes (of which there seems to be only one). Try creating a function like this:
Code:
public function VisitNode(TheNode as TreeNode)
{
   For each Node in TheNode.Nodes {
      VisitNode(Node);
      If TheNode.Checked {
         CheckedCount++;
      }
   }
}

You'd initialize your CheckedCount to zero, and then call the function like this:
Code:
  CheckedCount = 0;
  For each Node in TreeView1.Nodes {
    VisitNode(Node);
  }

Chip H.


Chip H.
 
Hey Chip,

Thanks for the response. We ended up using recursion to get it working the way we wanted to, you were bang on.
:)

A new problem though:
I'm trying to get an attribute from one of the nodes by accessing the
node.FindNodeAttribute("Attribute")
sub, but its not returning anything for hte specific attribute I'm looking for! To further the frustration, when I view the source, all the attributes are listed in the tag!

Is this just a bug in the treeview?!

Thanks,

Jack
 
Just to add to that last post, actually its NOT adding all of the attributes that I'm adding to the xml file that gets binded to the Treeview!

What the...?!?!?!?!

If I view the xml document that I create in memory before binding, it has all the proper attributes. As soon as I bind it, it drops off one of the attributes!

This is getting dumb
:(

Jack
 
heh, nm, all good. Figured out that there are only certain attributes that the treeview will pick up on, and have stored my data in the NodeData property of the node. Everything works kewl now
:)

Thanks,

jack
 
jfrost10 -

I was also going to suggest that in XML, attributes, element names, etc. are case-sensitive, and you should check that you aren't saying "MyAttribute" when you meant "mYaTTRIBUTE".

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top