CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 11/30/2005 3:14:21 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 3 Views: 272 Favorited: 0 Favorite
4 Items, 1 Pages 1 |< << Go >> >|
IthraelArlet
Asp.Net User
HOW TO: Expand Tree to SelectedNode11/30/2005 3:14:21 AM

0

I've seen this asked a couple times in various threads, so am posting a quick follow-up.  The following code allows you to automatically open a TreeView control that is being used for navigation to the current page, while closing all other nodes, similar to MSDN's behavior.  The benefits of this includes: a) For large sitemaps, keeps default navigation state small, and b) Provides users with immediate feedback as to where they are at within the site hierarchy (especially helpful for users being linked to a page remotely). 

The core function:

  void RevealDescendents(TreeNode treeNode) {
    if (treeNode == null) return;
    treeNode.Expanded = true;
    if (treeNode.Parent == null) return;
    RevealDescendents(treeNode.Parent);
    }

Then call:

  RevealDescendents(objTreeView.SelectedNode);

Important: If you are using declaritive syntax for adding nodes, you can do it in the standard Page_Load event; however, if you are using databinding then this must be done in PreRenderComplete (
reference, thanks to jdixon for this tip).  If your TreeView is in a master template or user control you may need to wireup the Page.PreRenderComplete() event as follows:

  Page.PreRenderComplete += new EventHandler(Page_PreRenderComplete);

I do this in my Page_Load event.  You can then add an event handler called Page_PreRenderComplete to the master template.  Again, this is only necessary if you are using databinding (e.g., binding to the web.sitemap file or any custom sitemap provider class).

Jeremy
Lee Dumond
Asp.Net User
Re: HOW TO: Expand Tree to SelectedNode12/6/2005 8:13:31 AM

0

I need to figure out a way to do this, but I don't know C#, only VB.

Essentially, I need to be able to reveal all the "ancestors" of the selected node back to the beginning, plus expand the selected node by one level, such that all the children (but not grandchildren, etc.) of that node are also revealed.

In other words, as I drill down into the tree, it will provide feedback back to the top of the tree on that branch only, plus reveal what's underneath the currently selected node.

I am desperate to get this done at this point. Again, I do need the solution in VB.

Thanks very much,

~ Lee


==================================================
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we all know you have been helped.
IthraelArlet
Asp.Net User
Re: HOW TO: Expand Tree to SelectedNode12/6/2005 10:34:50 PM

0

I don't know Visual Basic, but I think the code would look something like this:

  Sub RevealDescendents (treeNode As TreeNode) 
    if (treeNode Is Null) Return
    treeNode.Expanded = true
    if (treeNode.Parent Is Null) Return
    RevealDescendents(treeNode.Parent)
  End Sub

I'm not sure what the exact event wireup syntax is in VB to get around the Page_PreRenderComplete() issue, but once you wire that up this function should do the trick for you. 

Lee Dumond
Asp.Net User
Re: HOW TO: Expand Tree to SelectedNode12/11/2005 7:49:29 PM

0

Thanks for a brilliant piece of work here. That thing about the PreRenderComplete would have had me stumped for days.

This trick is very, very slick, and works perfectly. In case anyone is interested in doing it with VB:

The core function:

Protected Sub RevealDescendents(ByVal treeNode As TreeNode)
   If treeNode IsNot Nothing Then
      treeNode.Expand()
   Else
      Return
   
End If
   
If treeNode.Parent IsNot Nothing Then
      
RevealDescendents(treeNode.Parent)
   
Else
      
Return
   
End If
End Sub

Then, call the function as follows:

Public Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs)
   RevealDescendents(TreeViewMaster1.SelectedNode)
End Sub

Like the man said, if you want to do this with databinding, you need to handle it in PreRenderComplete. If you're using the tree on a Master page, you have to reference it from the content page by exposing the PreRenderComplete event like this:

Public Event PreRenderComplete As EventHandler

and wiring it up from Page_Load in the content page, as follows:

AddHandler PreRenderComplete, AddressOf Master.Page_PreRenderComplete

and that's it, VB style. Again, thanks for the solution, IthraelArlet!


==================================================
Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we all know you have been helped.
4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Database programming languages: 10th international symposium, DBPL 2005, Trondheim, Norway, August 28-29, 2005 : revised selected papers Authors: Gavin Bierman, Christoph Koch, Pages: 294, Published: 2005
Visual Basic 2005 Programming Black Book + With CD New Edition Authors: Steven Holzner, Pages: 1504, Published: 2006
Analysis and visualization tools for constraint programming: constraint debugging Authors: Pierre Deransart, Manuel Hermenegildo, Jan Małuszyński, Pages: 363, Published: 2000
Visual Basic .NET Programming Black Book + With CD 2003 Edition Authors: Steven Holzner, Pages: 1272, Published: 2005
Mastering Visual Basic .NET Authors: Evangelos Petroutsos, Pages: 1153, Published: 2002

Web:
ASP.NET Classic Controls - Treeview Forum - Refresh tree and ... NET: Treeview / Refresh tree and expand to previous selected node ... is the tree to refresh with the route to the currently selected node still being open. ...
Nabble - Dojo - Dojo Tree expand All child nodes of a selected node Dojo Tree expand All child nodes of a selected node. Hi All, Is it possible to expand all of the child nodes a selected node(except root node) ? By...
How to Expand and Collapse the Schema Trees To completely expand all or part of a schema tree. Select the node under which you want to completely expand the schema tree. The selected node must be a ...
Treeview Expand Selected Node On Postback - ASP.NET Forums See, since the tree is on the master page there will be actually ... As your description, you want to expand the node that you click on and ...
AMIS Technology blog » Blog Archive » Expand tree node all the way ... The tree will display the selected node in a highlighted fashion, .... One Response to “Expand tree node all the way down in the ADF Faces ...

HOW TO: Expand Tree to SelectedNode - ng.asp-net-forum ... HOW TO: Expand Tree to SelectedNode, > ROOT > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls, ...
Treeview Navigation - Expand and Collapse on Node click - ng.asp ... Dec 14, 2007 ... Once the selected node is known, need to expand the tree from the top level .... HOW TO: Expand Tree to SelectedNode - ng.asp-net-forum . ...
Treeview selectednode does not do what I expect - ng.asp-net-forum ... HOW TO: Expand Tree to SelectedNode - ng.asp-net-forum ... The following code allows you to automatically open a TreeView ... SelectedNode) End Sub. ...
How to set the selectedValue of a treeview ? - ng.asp-net-forum ... You can also run the example and it will expand and collapse like you want. Good Luck! HOW TO: Expand Tree to SelectedNode ...
Treeview with navigateurl and populateondemand does postback first ... HOW TO: Expand Tree to SelectedNode - ng.asp-net-forum ... treeview with navigateurl and populateondemand does postback first time each node ...






please help

link

find datakeys (datakeyfield) in nested datalist

web server and database server separated

paypal integration!!

page events doesn't show up in the drop down for c# but shows up for vb code.

linking to google maps, etc.

authentication tickets

hi to all

what is aspnet_setreg.exe??

get the weeknumber of the first & last day of the current month

end of statement and variables not dim. help

i am trying to render some html/gif during validatinsummary rendering?

almost there, need help adding to xml file . .

color chart like textbox properties's backcolor selection??

file attachment

dialog webform doesn't call page_load

response redirect

enable & disable

passing parameter values from one application layer to another

display db

a good asp book

open 10mb size excel file

error

web statistics

open any type of document from the server file system

accessing the value from a textbox control in one class in another class

variable scope

regular expression

help with focus on textbox

   
  Privacy | Contact Us
All Times Are GMT