TreeView Collapse and Expand Dynamicallyhttp://forums.asp.net/t/1048803.aspx/1?TreeView+Collapse+and+Expand+DynamicallyWed, 04 Jul 2007 08:41:53 -040010488031477113http://forums.asp.net/p/1048803/1477113.aspx/1?TreeView+Collapse+and+Expand+DynamicallyTreeView Collapse and Expand Dynamically <p>I have been trying for about 3 hours now to figure out how to dynamically expand and collapse treeView nodes.</p> <p>&nbsp;The treeView is databinded to a siteMap which looks like this:</p> <p>&nbsp;<font color="#0000ff" size="2">&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">default.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Home</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Home</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Home</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">calendar/view.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Calendar</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">View Calendar</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Calendar</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">events/list.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Events</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">List Events</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Events</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">events/manage.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage Events</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">ManageEvents</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">reminders/list.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Reminders</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">List Reminders</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Reminders</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">reminders/manage.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage Reminders</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">ManageReminders</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">contacts/list.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Contacts</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">List Contacts</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Contacts</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">contacts/add.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Add</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Add Contact</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">AddContacts</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">contacts/print.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Print</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Print Contacts</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">PrintContacts</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">contacts/import.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Import</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Import Contacts</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">ImportContacts</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">contacts/export.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Export</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Export Contacts</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">ExportContacts</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">links/list.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Links</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">List Links</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Links</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">links/manage.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage Links</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">ManageLinks</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt;</p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">files/list.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Files</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">List Files</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">Files</font><font size="2">&quot;</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">url</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">files/manage.aspx</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">title</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">description</font><font color="#0000ff" size="2"> =</font><font size="2">&quot;</font><font color="#0000ff" size="2">Manage Files</font><font size="2">&quot;</font><font color="#0000ff" size="2"> </font><font color="#ff0000" size="2">id</font><font color="#0000ff" size="2">=</font><font size="2">&quot;</font><font color="#0000ff" size="2">ManageFiles</font><font size="2">&quot;</font><font color="#0000ff" size="2">/&gt; </p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</p> <p>&lt;/</font><font color="#800000" size="2">siteMapNode</font><font color="#0000ff" size="2">&gt;</font></p> <p><font color="#0000ff" size="2"></font>&nbsp;</p> <p><font color="#0000ff" size="2">The treeView id=&quot;secNavMenu&quot;</font></p> <p><font color="#0000ff">Basically I have 2 issues.&nbsp; The second issue isn't too bad as I can live with it it.&nbsp; However if I can't figure out the first issue I'm gonna have to manually create &lt;nodes&gt;&lt;asp:treeviewnode&gt;.... on each page.</font></p> <p><font color="#0000ff">Issue#1 - using the sitemap above I'd like to dynamically collapse all nodes but the selected node.&nbsp; ie. if I'm on the calendar page I'd like all other nodes to be collapsed.&nbsp; I'd like to do this via the .aspx.vb pages for each page that I have.&nbsp; Otherwise I'll have to manually create the treeViews for each page!</font></p> <p><font color="#0000ff">Issue#2 - I can't seem to get it so that &quot;Home&quot; isn't the only Root node.&nbsp; The only way I could work it out so there are no was with all other nodes being children of Home.</font></p> <p><font color="#0000ff"></font>&nbsp;</p> <p><font color="#0000ff">Obviously I'm very new to asp.net and I would greatly appreciate any help!</font></p> <p><font color="#0000ff"></font>&nbsp;</p> <p><font color="#0000ff">Thanks,</font></p> <p><font color="#0000ff">Michael</font></p> <p><font color="#0000ff" size="2">&nbsp;</p> </font> 2006-11-27T02:34:50-05:001478147http://forums.asp.net/p/1048803/1478147.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p><font face="Courier New">Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs) <br> &nbsp;If e.Node.Parent Is Nothing Then <br> &nbsp; &nbsp;Return <br> &nbsp;End If <br> &nbsp;Dim tn As TreeNode = e.Node.Parent <br> &nbsp;For Each node As TreeNode In tn.ChildNodes <br> &nbsp; &nbsp;If Not (node = e.Node) Then <br> &nbsp; &nbsp; &nbsp;node.Collapse <br> &nbsp; &nbsp;End If <br> &nbsp;Next <br> End Sub</font></p> <p>overriding the expanded event as shown above should resolve your first issue.</p> <p>Regarding the second issue, I guess with the sitemap datasource, it is not doable. might be possible with other datasources.</p> <p>Hope it helped. Thanks</p> 2006-11-27T22:16:52-05:001478150http://forums.asp.net/p/1048803/1478150.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>The above would not work if more than one root so improved a little.</p> <p><font face="Courier New">Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs) <br> &nbsp;If e.Node.Parent Is Nothing Then <br> &nbsp; &nbsp;For Each node As TreeNode In (CType(ConversionHelpers.AsWorkaround(sender, GetType(TreeView)), TreeView)).Nodes <br> &nbsp; &nbsp; &nbsp;If Not (node = e.Node) Then <br> &nbsp; &nbsp; &nbsp; &nbsp;node.Collapse <br> &nbsp; &nbsp; &nbsp;End If <br> &nbsp; &nbsp;Next <br> &nbsp; &nbsp;Return <br> &nbsp;End If <br> &nbsp;Dim tn As TreeNode = e.Node.Parent <br> &nbsp;For Each node As TreeNode In tn.ChildNodes <br> &nbsp; &nbsp;If Not (node = e.Node) Then <br> &nbsp; &nbsp; &nbsp;node.Collapse <br> &nbsp; &nbsp;End If <br> &nbsp;Next <br> End Sub</font></p> <p><font face="Courier New"></font>&nbsp;</p> <p>Hope it helped. Thanks</p> 2006-11-27T22:27:50-05:001478207http://forums.asp.net/p/1048803/1478207.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>A few things:</p> <p>(1)&nbsp; It says that ConversionHelpers is not declared.&nbsp; (2) (node=e.node) says &quot;=&quot; is not defined for types 'system.web.ui.webcontrols.treenode.</p> <p>Also, What is it exactly that you are doing in the code above?&nbsp; See my questions underlined next to the code.</p> <p><font face="Courier New">Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs) <br> &nbsp;If e.Node.Parent Is Nothing Then <u>If there is no parent node than you'll collapse that node?</u><br> &nbsp;&nbsp;&nbsp;For Each node As TreeNode In (CType(ConversionHelpers.AsWorkaround(sender, GetType(TreeView)), TreeView)).Nodes<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If Not (node = e.Node) Then&nbsp;<u>I'm not sure what this For statement does.&nbsp; What is the ctype(conversionhelpers.....? </u><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node.Collapse&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u>what are you looking for in [not(node=e.node)]?</u><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If <br> &nbsp; &nbsp;Next <br> &nbsp; &nbsp;Return <br> &nbsp;End If <br> &nbsp;Dim tn As TreeNode = e.Node.Parent <br> &nbsp;For Each node As TreeNode In tn.ChildNodes <br> &nbsp; &nbsp;If Not (node = e.Node) Then <br> &nbsp; &nbsp; &nbsp;node.Collapse <br> &nbsp; &nbsp;End If <br> &nbsp;Next <br> End Sub</font></p> <p><font face="Courier New"></font>&nbsp;</p> <p><font face="Courier New">Thanks for the help!</font></p> <p><font face="Courier New">Michael</font></p> 2006-11-27T23:42:24-05:001478209http://forums.asp.net/p/1048803/1478209.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>Oh, one more thing.&nbsp; I'm not sure that it is possible using the TreeView but I would like to use the root nodes as primary navigation at the top of the screen and the childNodes as the secondary navigation on the left side of the screen.&nbsp; When you click on the primary nav node I'd like it to only expand or display the secondary navigation of that node.</p> <p>Michael</p> 2006-11-27T23:45:16-05:001478288http://forums.asp.net/p/1048803/1478288.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>sorry about that I had used the conversion (C# to VB) tool from here http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx</p> <p>&nbsp;</p> <p>Just replace the older one with</p> <p>Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeExpanded<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If e.Node.Parent Is Nothing Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each node As TreeNode In (CType(sender, TreeView)).Nodes<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not (node.Equals(e.Node)) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node.Collapse()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Return<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim tn As TreeNode = e.Node.Parent<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each node As TreeNode In tn.ChildNodes<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not (node.Equals(e.Node)) Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node.Collapse()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (e.Node.Depth = 1) Then<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> <br> &nbsp;&nbsp;&nbsp; End Sub</p> <p>&nbsp;</p> <p>Regarding the new layout. Can you explain a little more of what you are trying to do?</p> <p>Thanks</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br> &nbsp;</p> <p>&nbsp;</p> 2006-11-28T01:22:03-05:001478309http://forums.asp.net/p/1048803/1478309.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>remove these lines&nbsp;</p> <p>If (e.Node.Depth = 1) Then<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</p> 2006-11-28T01:39:46-05:001479096http://forums.asp.net/p/1048803/1479096.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>Thanks a lot.&nbsp; I'll try this out when I get home.</p> <p>Regarding what I'm trying to do:</p> <p>I have all primary navigation at the top (Home, Calendar, Contacts, Links, Files)</p> <p>I'd like to have all sub navigation on the left.&nbsp; When you click &quot;Home&quot; the entire treeview should display to the left.&nbsp; However, when you click on &quot;Calendar&quot; only the subnavigation for Calendar should display on the left.&nbsp; It should be like this for Contacts, Links, Files.... Home is the only primary nav that will list more than just it's own sub navigation.</p> <p>I can easily do this by manually creating the &lt;asp:treeview&gt; but I would like to figure out a better way to do it using the sitemap.&nbsp; I would also like to use a master page but I am having some difficulty getting the pages to display correctly but I'll figure that out later.</p> <p>Michael</p> 2006-11-28T15:36:34-05:001479111http://forums.asp.net/p/1048803/1479111.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>For this purpose you can use the menu control instead with horizontal alignment. In fact I am currently using it in the present project. I am not sure we can do it with TreeView (at least the name sounds like tree).</p> <p>Thanks.</p> 2006-11-28T15:50:24-05:001479318http://forums.asp.net/p/1048803/1479318.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically I am using the menu control with horizontal orientation for the primary (top) navigation.&nbsp; However, I didn't see how using the menu control would do what I was looking for in regards to the secondary (left side) navigation. 2006-11-28T18:56:03-05:001479362http://forums.asp.net/p/1048803/1479362.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically oh I just had the top thing in mind and forgot about the left only options. Sorry. 2006-11-28T19:33:58-05:001786475http://forums.asp.net/p/1048803/1786475.aspx/1?Re+TreeView+Collapse+and+Expand+DynamicallyRe: TreeView Collapse and Expand Dynamically <p>i m retrieving the nodes from database.How to give the url to that nodes</p> 2007-07-04T08:41:53-04:00