I'm just new to all this too but i had a simular problem , only i use ajax with the treeview but i think it'll work the same
In ur treeview1_selectednodechange
dim openNode as string
'What i'm doing here is actually determining the valuepath of the selected node , and pulling out the level you want to be open , so in my case it's
lvl1
lv2
lvl2
lvl2
And only 1 lvl1 can be open at one time after selecting
If Not TreeView1.SelectedNode.ValuePath = "0" Then
openNode = TreeView1.SelectedNode.ValuePath
openNode = Mid(TreeView1.SelectedNode.ValuePath, 3, 1)
OpenOneNode(
CInt(openNode))
End If
Here i just enumerate through the lvl2 nodes , and check the part of the valuepath against that of the selected node part valuepath , if they match up , it expands , all the rest is collapsed.
Protected Sub OpenOneNode(ByVal opennode As Integer)
Dim a As New TreeNode
For Each a In TreeView1.Nodes(0).ChildNodes
If Mid(a.ValuePath, 3, 1) = opennode Then
a.Expand()
Else
a.CollapseAll()
End If
Next
End Sub
Hope it helps for you , it did the trick for me