Link to home
Create AccountLog in
Avatar of ratkinso666
ratkinso666

asked on

Start Treeview collapsed

Hi all, I have a hopefully simple one, when I start my page it starts with my treeview fully expanded.  I want it to start at 1 level down.  I have tried loading into my
page_load
TreeView1.Nodes(1).CollapseAll
and I tried
TreeView1.Nodes(1).Expanded = False
I tried changing various variables in properties, but no help...
This is loaded in the MasterPage and uses a SiteMapDataSource with a web.sitemap...
Thanks,
Randy
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

If you you want the first level and it's children visible you can do it like this:

Dim node, node2 As TreeNode
For Each node In Treeview1.Nodes
  For Each node2 In node.ChildNodes
    node2.CollapseAll()
  Next
Next

If you just want the first level you do:

Treeview1.CollapseAll()
Avatar of ratkinso666
ratkinso666

ASKER

It does not seem to make a difference...
But I did notice that the Treeview1.Nodes count is 0
Ok, you're doing this too early.

You must do it after the databinding is done. Do it in Page_PreRender instead.
Here is a section of my Web.sitemap, perhaps I am not entering the different nodes correctly...


<siteMapNode url="http://web1/" title="Home"  description="">
      <siteMapNode url="Accounting\AccountingHome.aspx" title="Accounting"  description="">
        <siteMapNode url="PaymentStatus\AP_PaymentStatus.aspx" title="AP Payment Status"  description="">
        </siteMapNode>            
        <siteMapNode url="http://web1/HydroChemWebsite/Accounting/SupplierContactList.xls" title="Supplier Contact List"  description="">
        </siteMapNode>
      </siteMapNode>
      <siteMapNode url="AllianceGroup\AllianceGroupHome.aspx" title="Alliance Group"  description="">
        <siteMapNode url="http://AllianceContacts.asp?Section=Alliance" title="Contacts"  description="">
        </siteMapNode>       
        <siteMapNode url="http://Reports/Report_CustomerOT.aspx" title="Customer OT Rpt"  description="">
        </siteMapNode>
      </siteMapNode>
</siteMapNode>

Open in new window

I changed it to there and get the same result.  In the
For Each node In TreeView1.Nodes
there are 0 nodes at that point, so it just skips right on by that and its inner loop..
ASKER CERTIFIED SOLUTION
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks, that one worked.  I could have sworn I had already tried that one, but I have been messing with several of them, so I probably changed it and then tested it in a different one than the one I had changed it in.
Thanks for the great help!!
thanks again for the great help, it is appreciated