Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
当单击节点时,选定的节点展开,同层的其它节点关闭。。
Dim nd As WinForm.TreeNode = trv.SelectedNode
Dim id As Integer = nd.index
If e.Node.Level = 0 Then
Dim cnt As Integer = trv.Nodes.Count - 1
For i As Integer = cnt To 0 Step -1
If trv.Nodes.Count >= 0 Then
If i=id
trv.Nodes(i).Expand()
Else
trv.Nodes(i).Collapse()
End If
End If
Next
ElseIf e.Node.Level = 1 Then
Dim cnt As Integer = trv.Nodes.Count - 1
For i As Integer = cnt To 0 Step -1
If trv.Nodes.Count >= 0 Then
If i=id
trv.Nodes(i).Nodes(i).Expand()
Else
trv.Nodes(i).Nodes(i).Collapse()
End If
End If
Next
End If
这个只能做到根节点,往下的就出错了。。。
用这个比较好:
http://www.foxtable.com/help/topics/2302.htm
大概就是这样:
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath then
trv.Nodes(i).Collapse()
End If
Next
e.Node.Expand()
。。。谢狐爸
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
If e.Node.Level = 0 Then
Dim cnt As Integer = trv.Nodes.Count - 1
For i As Integer = cnt To 0 Step -1
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
trv.Nodes(i).CollapseAll()
Else
e.Node.Expand()
End If
Next
Next
ElseIf e.Node.Level = 1 Then
Dim cnt As Integer = trv.SelectedNode.ParentNode.Nodes.Count - 1
For i As Integer = cnt To 0 Step -1
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
trv.Nodes(Value(0)).Nodes(i).CollapseAll()
Else
e.Node.Expand()
End If
Next
Next
ElseIf e.Node.Level = 2 Then
Dim cnt As Integer = trv.SelectedNode.ParentNode.Nodes.Count - 1
For i As Integer = cnt To 0 Step -1
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
trv.Nodes(Value(0)).Nodes(Value(1)).Nodes(i).CollapseAll()
Else
e.Node.Expand()
End If
Next
Next
ElseIf e.Node.Level = 3 Then
Dim cnt As Integer = trv.SelectedNode.ParentNode.Nodes.Count - 1
For i As Integer = cnt To 0 Step -1
For Each nd As WinForm.TreeNode In trv.AllNodes
If nd.Level = e.Node.Level AndAlso nd.FullPath <> e.Node.FullPath Then
trv.Nodes(Value(0)).Nodes(Value(1)).Nodes(Value(2)).Nodes(i).CollapseAll()
Else
e.Node.Expand()
End If
Next
Next
End If
可不可以简化代码 不管目录树的层数。。。?
单击展开,这样不就行了吗:
e.Node.Expand()