Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > TreeNodeCollection & TreeNode not defined

Reply
Thread Tools

TreeNodeCollection & TreeNode not defined

 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      10-20-2004
I have this code below.
All its suppose to do is to EXPAND / COLLAPSE ALL of my treeview.
But when i use ASP.NET WEbmatrix it all works fine ..

But with VS.NET is says TreeNodeCollection not defined
and TreeNode not defined!!!!!!!!!!!!!!arg!!!!

How am i suppose to define it in VS.NET..
OR Does anybody another way of doing it!!
Any help appreciated!


Private Sub expandAll(ByVal sender As Object, ByVal e As EventArgs)
'Call the recursive function with the rootnode collection and a
boolean value indication to expand the nodes.
expandCollapseAllTreeviewNodes(Me.tvFamilyTree.Nod es, True)
End Sub

Private Sub collapseAll(ByVal sender As Object, ByVal e As EventArgs)
'Call the recursive function with the rootnode collection and a
boolean value indication to collapse the nodes.
expandCollapseAllTreeviewNodes(Me.tvFamilyTree.Nod es, False)
End Sub

'Recursive function.
Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
TreeNodeCollection, ByVal expand As Boolean)
Dim node As TreeNode

'Loop through each node of the collection and expand it.
For Each node In nodes
node.Expanded = expand

'Call the recursive function from itself, just the subnode
collection (this will ensure all nodes either are collapsed or expanded).
expandCollapseAllTreeviewNodes(node.Nodes, expand)

Next
End Sub

ASP.NET
-----------
<asp:Button id="Button1" onclick="expandAll" runat=server
Text="Expand"></asp:Button>
<asp:Button id="Button2" onclick="collapseAll"
Text="Collapse"></asp:Button>

 
Reply With Quote
 
 
 
 
Mohamed El Ashmawy
Guest
Posts: n/a
 
      10-20-2004
Hello Patrick,
I tried the scenario as follows and it worked.
I added a tree view class to my web page in vs.net 2003 and created nodes
in it.
I added 2 buttons and inserted the code you sent in your e-mail (changed
Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)


I ran the project and pressed the collapse and exapnd buttons. Things
worked as expected and exapnsion and collapsing worked fine.


Is there a special case that you are having in your treeview?
Are the nodes created dynamically? I created my nodes statically here?

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC

 
Reply With Quote
 
 
 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      10-21-2004
thx Mohammed.
My treeView is populsted using XML
And my code works well in ASP.NET WEMATRIX
Only when i use Visual Studio it says :- TreeNodeCollection and TreeNode
are not defined.
How should i define that..
Can you just post your full code i guess it will help me!
Thanks!!



""Mohamed El Ashmawy"" wrote:

> Hello Patrick,
> I tried the scenario as follows and it worked.
> I added a tree view class to my web page in vs.net 2003 and created nodes
> in it.
> I added 2 buttons and inserted the code you sent in your e-mail (changed
> Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)
>
>
> I ran the project and pressed the collapse and exapnd buttons. Things
> worked as expected and exapnsion and collapsing worked fine.
>
>
> Is there a special case that you are having in your treeview?
> Are the nodes created dynamically? I created my nodes statically here?
>
> Regards
> Mohamed El Ashmawy
> MEA Developer Support Center
> ITWorx on behalf of Microsoft EMEA GTSC
>
>

 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      10-21-2004
thx Mohammed.
My treeView is populsted using XML
And my code works well in ASP.NET WEMATRIX
Only when i use Visual Studio it says :- TreeNodeCollection and TreeNode
are not defined.
How should i define that..
Can you just post your full code i guess it will help me!
Thanks!!


""Mohamed El Ashmawy"" wrote:

> Hello Patrick,
> I tried the scenario as follows and it worked.
> I added a tree view class to my web page in vs.net 2003 and created nodes
> in it.
> I added 2 buttons and inserted the code you sent in your e-mail (changed
> Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)
>
>
> I ran the project and pressed the collapse and exapnd buttons. Things
> worked as expected and exapnsion and collapsing worked fine.
>
>
> Is there a special case that you are having in your treeview?
> Are the nodes created dynamically? I created my nodes statically here?
>
> Regards
> Mohamed El Ashmawy
> MEA Developer Support Center
> ITWorx on behalf of Microsoft EMEA GTSC
>
>

 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      10-22-2004
Thx Mohammed....
The Expand Collapse is working good now.
But i don't know whether u noticed someting funny about it.
When u EXPAND the Nodes and then select a node and then Press Collapse it
gives Error:-

"SelectedNodeIndex cannot be set to an undisplayed node (all parents of a
selected node must be expanded)"

Let me kow how you go!!!


""Mohamed El Ashmawy"" wrote:

> Hello Patrick,
> I tried the scenario as follows and it worked.
> I added a tree view class to my web page in vs.net 2003 and created nodes
> in it.
> I added 2 buttons and inserted the code you sent in your e-mail (changed
> Me.tvFamilyTree.Nodes to Me.TreeView1.Nodes)
>
>
> I ran the project and pressed the collapse and exapnd buttons. Things
> worked as expected and exapnsion and collapsing worked fine.
>
>
> Is there a special case that you are having in your treeview?
> Are the nodes created dynamically? I created my nodes statically here?
>
> Regards
> Mohamed El Ashmawy
> MEA Developer Support Center
> ITWorx on behalf of Microsoft EMEA GTSC
>
>

 
Reply With Quote
 
Mohamed El Ashmawy
Guest
Posts: n/a
 
      11-19-2004
Hello Patrick,
I am sorry for the delay in my reply.
I am happy that the exapnd/collapse problem is over.
As for the error you get. It means that you are trying to set the selection
for a node that is under collapsed node (i.e. the node you are selecting is
actually not apparent on the screen).
Do you have code in your pageload event that selects a specific node? If
so, then you need to check that all the node hierarchy (from that node to
the root) as expanded. If not, then don't select the node.

The problem you described is not apparent on my side because I don't have
any code that selects a node.
The code I am using is taken from the code you posted and here it is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, True)

End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, False)
End Sub

Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
TreeNodeCollection, ByVal expand As Boolean)
Dim node As TreeNode

'Loop through each node of the collection and expand it.
For Each node In nodes
node.Expanded = expand

'Call the recursive function from itself, just the subnode
collection (this will ensure all nodes either are collapsed or expanded).
expandCollapseAllTreeviewNodes(node.Nodes, expand)

Next
End Sub


As for the treeview contents, they are all statically added using the
VS.Net IDE

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC

 
Reply With Quote
 
Patrick.O.Ige
Guest
Posts: n/a
 
      11-20-2004
Thx for the reply mohammed!
I will check my code again and get back to you...
What my question is again is that when i collapse why does it collapse
totally..
I want it to collpapse to top nodes only and cot collapse to the root node.
Thx
Patrick

""Mohamed El Ashmawy"" wrote:

> Hello Patrick,
> I am sorry for the delay in my reply.
> I am happy that the exapnd/collapse problem is over.
> As for the error you get. It means that you are trying to set the selection
> for a node that is under collapsed node (i.e. the node you are selecting is
> actually not apparent on the screen).
> Do you have code in your pageload event that selects a specific node? If
> so, then you need to check that all the node hierarchy (from that node to
> the root) as expanded. If not, then don't select the node.
>
> The problem you described is not apparent on my side because I don't have
> any code that selects a node.
> The code I am using is taken from the code you posted and here it is:
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, True)
>
> End Sub
>
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> expandCollapseAllTreeviewNodes(Me.TreeView1.Nodes, False)
> End Sub
>
> Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
> TreeNodeCollection, ByVal expand As Boolean)
> Dim node As TreeNode
>
> 'Loop through each node of the collection and expand it.
> For Each node In nodes
> node.Expanded = expand
>
> 'Call the recursive function from itself, just the subnode
> collection (this will ensure all nodes either are collapsed or expanded).
> expandCollapseAllTreeviewNodes(node.Nodes, expand)
>
> Next
> End Sub
>
>
> As for the treeview contents, they are all statically added using the
> VS.Net IDE
>
> Regards
> Mohamed El Ashmawy
> MEA Developer Support Center
> ITWorx on behalf of Microsoft EMEA GTSC
>
>

 
Reply With Quote
 
naija naija
Guest
Posts: n/a
 
      11-22-2004
Hi Mohamed El Ashmawy,
Thx for the response!
I have looked through the code again but i still get the same error(I
get the error only when i select a node and i click to collapse!And
again when i select ROOT it collapse with no error but IT COLLAPSE
TOTALLY TO THE ROOT LEVEL):-

"The node at index 0.1 is not currently displayed in the tree.
SelectedNodeIndex cannot be set to an undisplayed node (all parents of a
selected node must be expanded)."

And i don't have any code in the Page_Load.
the code 'm using looks like this:-

Private Sub expandCollapseAllTreeviewNodes(ByVal nodes As
TreeNodeCollection, ByVal expand As Boolean)
Dim node As TreeNode

'Loop through each node of the collection and expand it.
For Each node In nodes
node.Expanded = expand

'Call the recursive function from itself, just the subnode
collection (this will ensure all nodes either are collapsed or
expanded).
expandCollapseAllTreeviewNodes(node.Nodes, expand)

Next
End Sub


Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nod es, False)
End Sub 'Button2_Click

Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.expandCollapseAllTreeviewNodes(tvFamilyTree.Nod es, True)
End Sub 'Button2_Click

Thx Mohammed and let me read from you.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Mohamed El Ashmawy
Guest
Posts: n/a
 
      11-23-2004
Hello Patrick,
The function that you have "expandCollapseAllTreeviewNodes" expands or
collapses all the nodes. This function iterates through all the nodes and
collapses them all. i.e. This is the behavior expected of your code.
If you want to collapse the selected node only you should write code like
this one:
Dim node As TreeNode =
Me.TreeView1.GetNodeFromIndex(Me.TreeView1.Selecte dNodeIndex)
node.Expanded = False

Since your code collapses all node to the root. If you have a node
selected, then this would give the error you get.
Thus, you should specify the needed behavior and re-implement the collapse
method according to your requirements.

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC

 
Reply With Quote
 
naija naija
Guest
Posts: n/a
 
      11-24-2004
Mohamed El Ashmawy,
Thx for the reply.
What i just want is just for the Node to expand all the nodes and
Collapse(Not to the root but to the Sub Nodes)
Can you pls POST me the full code or forward me the resources to do
this!
Thx alot!




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User-defined exception: "global name 'TestRunError' is not defined" jmike@alum.mit.edu Python 1 07-10-2008 12:37 PM
what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode tanya foster ASP .Net 3 05-18-2006 05:58 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
'Controls' is not a member of 'Microsoft.Web.UI.WebControls.TreeNode' Patrick Olurotimi Ige ASP .Net 2 02-15-2005 10:47 AM
populating treeview menu from db(treenode not defined error) naijacoder naijacoder ASP .Net 1 09-15-2004 03:11 AM



Advertisments