2012-02-13 76 views
-1

我有下面的代码从数据库加载树视图问题是,当我点击叶节点时,它折叠到父节点任何一个请告诉我如何设置叶节点保持打开 更新代码 这我的完整代码通过whic我正在填充我的树形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 

请任何一个可以告诉我,我该如何设置叶节点为保持开放当它通过这段代码点击它

回答

0

很难理解逻辑,sinc Ë你没有提供有关事件的代码,而是从一个一目了然的代码,你应该尝试删除线

child1.Collapse() 

从程序

FillChild1 
+0

我也删除child.Expand(),但现在TreeView Expanded to Parent节点,并且当我在叶节点上展开一个dclick时,它会折叠到父节点,并且我知道哪个叶子打开了当前 – user1103342 2012-02-13 10:18:58

+0

要尝试帮助您,我认为我需要查看更多代码,尤其是一个你与事件相关联。 – 2012-02-13 10:36:19

+0

我在这里,只是注意到你正在使用网络控制:)对不起,我目前没有足够的关于网络资料的知识来帮助你。 – 2012-02-13 11:27:54

相关问题