我的目的是要遍历树的所有节点,以上代码是在Button_clicked事件里触发。
又出现“命令'TreeView1.Nodes.Count'无效。”的错误,Why?

解决方案 »

  1.   

    去看看
    http://expert.csdn.net/Expert/topic/901/901558.xml?temp=.2180139
    http://www.dotnetjunkies.com/howto/default.aspx?id=33
      

  2.   

    http://expert.csdn.net/expert/topic/919/919435.xml
      

  3.   

    遍历Treeview时,如何获得每个节点的父节点的ID?
      

  4.   

    Private Function GetNdCol(ByVal idx As String) As TreeNodeCollection
       '获得选中节点的父节点的Nodes集合  
       Dim cnt As Integer, i As Integer
       Dim tmpNds As TreeNodeCollection
       Dim idxs() As String
       idxs = Split(idx, ".")
       cnt = UBound(idxs)
       If cnt = 0 Then
           tmpNds = TreeView1.Nodes
       Else
           tmpNds = TreeView1.Nodes(CInt(idxs(0))).Nodes
           For i = 1 To cnt - 1
               tmpNds = tmpNds(CInt(idxs(i))).Nodes
           Next
       End If
       Return tmpNds
    End Function