求asp.net中树形图用treeview如何实现的代码(vb.net)!谢谢
解决方案 »
- Discuz(dotnet3.5免安装版)论坛中的两个引用文件
- 求下面代码能在火狐浏览器上运行
- ItemArray索引超出了数组界限and 这条insert语句到底这么写
- 求一个中美时间转换的程序
- 一个定时无刷新页面的问题
- 在ASP.NET页面中怎么做一个置顶按钮导航,功能很简单的,就是跳转而已!请高手指点!
- iis问题。
- asp.net 请问大家,那里有功能齐全一点的OA演示网站,请给我绍下(现在的我是井底蛙,自已的OA没有被认可)
- 在DataGrid中使用Button的问题
- 求助:关于office web components的资料
- 关于在datagrid中点击修改后,这行的某一列出现dropdownlist,更新后dripdownlist消失出现选好的值
- Help!!!
With Me.TreeView1.Nodes
'add text
.Add("AddByText")
'since with..end with is used: read TreeView1.Nodes.Add .... 'every add method returns the newly created node. You can use
'this concept set the result to a variable or to directly add
'a childnode:
.Add("AddByText2").Nodes.Add("ChildOfAddByText") 'this, you can take as far as you want
.Add("AddByText3").Nodes.Add("ChildOfAddByText").Nodes.Add("Another child") '--
N = .Add("AddByText, Attach To Variable")
N.Nodes.Add("Child one")
N.Nodes.Add("Child two")
' --
With .Add("AddByText Use WithTo Add ChildNodes").Nodes
.Add("Child 1")
.Add("Child 2")
.Add("Child 3").Nodes.Add("Subchild 1")
End With
End With 'for clarity, from here on, the treeview1 name will be added.
'In everyday use, you'll probably find the use of with..end with
'a lot easier (I know I do..) 'Method 2: adding by node
'Like virtually every .Net method you can directly assign an object:
Me.TreeView1.Nodes.Add(New TreeNode("AddByNode")) 'check out the overloading possibilities of using New()
'Another advantage of this method is that you can add a complete branch.
'(N is already declared as TreeNode above)
N = New TreeNode("MainNodeToAdd")
N.Nodes.Add("Child 1")
N.Nodes.Add("Child 2") 'you can for instance add this newly created node to all main branches:
Dim enumNode As TreeNode
For Each enumNode In TreeView1.Nodes
enumNode.Nodes.Add(N.Clone) '<- the clone() method is needed
Next 'Adding will always add the the node at the end of the collection.
'Of course you can also insert at a specified location:
Me.TreeView1.Nodes.Insert(2, New TreeNode("I am inserted at the 3th position")) 'removing is done much in the same way:
N = TreeView1.Nodes.Add("I need to be removed").Nodes.Add("and all children too")
TreeView1.Nodes.Remove(N) 'to clear all branches of any node you can use clear()
N.Nodes.Add("This child you will not see")
N.Nodes.Clear() 'if you use Clear on the treeview nodes itself, you
' would once again have an empty treeview 'once an item has been added, it is part of the item collection in nodes
'this means you can access it by its index
TreeView1.Nodes(0).Text = "I have index 0" 'the behaviour of the treenode can be controlled completely in code.
'you can make it expand
TreeView1.Nodes(0).Expand() 'and retract again
TreeView1.Nodes(0).Collapse()