TreeView叶节点未保留打开状态

时间:2012-02-13 08:58:50

标签: vb.net treeview

我有以下代码从DB加载树视图问题是,当我点击叶节点它崩溃到父节点任何一个请告诉我如何设置叶节点保持打开 更新代码 这是我的完整代码通过我填充我的Treeview

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      fill_Tree2()
  End Sub
  Private Sub fill_Tree2()
      Dim PrSet As DataSet = PDataset("Select * from GPS_TREE_PROV")
      TreeView1.Nodes.Clear()
      For Each dr As DataRow In PrSet.Tables(0).Rows
          Dim tnParent As New TreeNode()
          tnParent.Text = dr("Prov_name").ToString()
          tnParent.Value = dr("prov_id").ToString()
          tnParent.PopulateOnDemand = False
          tnParent.SelectAction = TreeNodeSelectAction.Expand
          tnParent.Expand()
          tnParent.Selected = True
          tnParent.ToolTip = tnParent.Text
          'tnParent.CollapseAll()
          TreeView1.Nodes.Add(tnParent)
          FillChild(tnParent, tnParent.Value)
      Next
  End Sub
  Public Sub FillChild(ByVal parent As TreeNode, ByVal ParentId As String)
      Dim ds As DataSet = PDataset("Select * from GPS_Tree_STA where Prov_ID =" & ParentId)
      parent.ChildNodes.Clear()
      Dim tnParent As New TreeNode()
      For Each dr As DataRow In ds.Tables(0).Rows
          Dim child As New TreeNode()
          child.Text = dr("sta_name").ToString().Trim()
          child.Value = dr("sta_id").ToString().Trim()
          'If Not child.ChildNodes.Count = 0 Then
          '   child.PopulateOnDemand = False
          'End If
          child.ToolTip = child.Text
          'child.SelectAction = TreeNodeSelectAction.Select
          'child.CollapseAll()
          'child.Expand()
          parent.ChildNodes.Add(child)
          FillChild1(child, child.Value)
      Next dr
  End Sub
  Public Sub FillChild1(ByVal parent1 As TreeNode, ByVal ParentId1 As String)
      Dim ds As DataSet = PDataset("Select * from GPS_Tree_TEHS where STA_ID =" & ParentId1)
      parent1.ChildNodes.Clear()
      For Each dr1 As DataRow In ds.Tables(0).Rows
          Dim child1 As New TreeNode()
          child1.Text = dr1("tehs_name").ToString().Trim()
          child1.Value = dr1("tehs_id").ToString().Trim()
          'If Not child1.ChildNodes.Count = 0 Then
          '  child1.PopulateOnDemand = False
          '   child1.Expand()
          'End If
          child1.ToolTip = child1.Text
          child1.SelectAction = TreeNodeSelectAction.Select
          child1.Expanded = True
          parent1.ChildNodes.Add(child1)
      Next
  End Sub
  Protected Function PDataset(ByVal Select_Statement As String) As DataSet
      Dim SqlCon As New OleDbConnection
      SqlCon = New OleDbConnection("Data Source=sml; User ID=sml; Password=sml; provider=OraOLEDB.Oracle")
      Dim da As New OleDbDataAdapter(Select_Statement, SqlCon)
      Dim ds As New DataSet()
      da.Fill(ds)
      Return ds
  End Function

请任何一个告诉我如何通过此代码点击Leaf节点时将Leaf节点设置为剩余打开

1 个答案:

答案 0 :(得分:0)

很难理解逻辑,因为你没有提供与事件相关的代码,但是从一瞥到你应该尝试删除代码的代码

child1.Collapse() 

来自程序

FillChild1