你少写东西了,看看范例
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
CreateDataSet() 
intiTree(TreeView1.Nodes, 0) 
End Sub 
Private Sub intiTree(ByRef Nds As TreeNodeCollection, ByVal parentId As Integer) 
Dim dv As New DataView() 
Dim drv As DataRowView 
Dim tmpNd As TreeNode 
Dim intId As Integer 
dv.Table = ds.Tables("tree") 
dv.RowFilter = "PARENTID=’" & parentId & "’" 
For Each drv In dv 
tmpNd = New TreeNode() 
strId = drv("NODE_ID") 
tmpNd.ID = strId 
tmpNd.Text = drv("NODE_NAME ") 
tmpNd.ImageUrl = drv("ICON").ToString 
Nds.Add(tmpNd) 
intiTree(Nds(Nds.Count - 1).Nodes, intId) 
Next 
End Sub

解决方案 »

  1.   

    没有少写东西啊,你的代码,intid永远等于0,肯定不对。
      

  2.   

    CreateDataSet() 这个怎么没有代码,能不能让看看
      

  3.   

    Private Sub CreateDataSet()’建立数据集 
    Dim myConn As New SqlConnection() 
    Dim myCmd As New SqlCommand("select NODEID,NODENAME,PARENTID,ADDRESS,ICON from Tree_info", myConn) 
    Dim myDataAdapter As New SqlDataAdapter() 
    myConn.ConnectionString = Application("connectstring") 
    myCmd.CommandText = "" 
    myCmd.Connection = myConn 
    myDataAdapter.SelectCommand = myCmd 
    myDataAdapter.Fill(ds, "tree") 
    End Sub 
    这些代码是别人的,我知道里面有毛病啊,我用c#改好了的,他的思路是正确的,错误的地方就是把intiTree(Nds(Nds.Count - 1).Nodes, intId) 换成intiTree(Nds(Nds.Count - 1).Nodes, strId) ,其它语法错误也写错了好几个,你自己看看把,要是需要c#的我倒可以给你帖一下
      

  4.   

    楼上的,能不能给我份完整的VB代码,我会C#昨天改用C#改,改不成,谢谢
      

  5.   

    to  seesea125(雨天)  ,如果改为strid,,则代和我的一样啊,可就是不行,
    快帮我啊
      

  6.   

    http://www.developersdex.com/gurus/articles/407.asp?Page=2
      

  7.   

    http://www.aspalliance.com/jamesavery/webcontrols/treeviewp2.aspx
      

  8.   

    http://expert.csdn.net/Expert/topic/2093/2093882.xml?temp=5.254763E-02
      

  9.   

    昨天回去我用vb调试了一下,程序和你的一样,却没有出现这样的问题,我建了8级都没有问题,我想有可能是数据库或treeview的属性设置问题,需要的话QQ传给你我的代码和数据库看看