<rp id="wnpn7"><ruby id="wnpn7"></ruby></rp>
<progress id="wnpn7"><track id="wnpn7"><rt id="wnpn7"></rt></track></progress>
<ruby id="wnpn7"></ruby>
<ruby id="wnpn7"><blockquote id="wnpn7"><div id="wnpn7"></div></blockquote></ruby>

    1. <em id="wnpn7"><ruby id="wnpn7"><input id="wnpn7"></input></ruby></em>
      1. <button id="wnpn7"><acronym id="wnpn7"></acronym></button><button id="wnpn7"><acronym id="wnpn7"></acronym></button>

        <rp id="wnpn7"><acronym id="wnpn7"></acronym></rp>

        <li id="wnpn7"><object id="wnpn7"><u id="wnpn7"></u></object></li>
        VB.net 2010 視頻教程 VB.net 2010 視頻教程 python基礎視頻教程
        SQL Server 2008 視頻教程 c#入門經典教程 Visual Basic從門到精通視頻教程
        當前位置:
        首頁 > 編程開發 > VBnet >
        • VB.net遍歷搜索Treeview,找到符合字符串條件的節點

        ListView具有和Treeview相同的內容,且都有Check屬性,帶有復選框,現在想讓ListView和Treeview的check選擇對應起來:
         
                For i = 0 To ListView2.Items.Count - 1
                    ListView2.Items(i).Checked = False '先清除所有選擇
                Next
                For Each n As TreeNode In GetCheck(TreeView1.Nodes)
                    If n.Level = 1 Then  '只處理子節點,不處理根節點
                        'Trace.WriteLine(n.Text & "," & n.Level.ToString)
                        For i = 0 To ListView2.Items.Count - 1
                            If ListView2.Items(i).SubItems(1).Text = n.Text Then  '與TreeView同步選擇
                                ListView2.Items(i).Checked = True
                            End If
                        Next
                    End If
                Next
         
        ' 遞歸搜索
            Private Function GetCheck(ByVal node As TreeNodeCollection) As List(Of TreeNode)
                Dim lN As New List(Of TreeNode)
                For Each n As TreeNode In node
                    If n.Checked Then lN.Add(n)
                    lN.AddRange(GetCheck(n.Nodes))
                Next
                Return lN
            End Function
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        反之,想讓Treeview和ListView的Check選擇對應:
         
            For Each node In TreeView1.Nodes
                NodeAllCheck(node, False)  '先清除所有選擇
            Next
            For i As Integer = 0 To ListView2.CheckedItems.Count - 1 '遍歷表格
                For Each node In TreeView1.Nodes  '根據表格選擇情況,選擇對應目錄樹節點
                    CheckNode(node, ListView2.CheckedItems(i).SubItems(1).Text) '遞歸搜索子節點
                Next
            Next
        Private Sub CheckNode(ByVal N As TreeNode, ByVal s As String)
            Dim node As TreeNode
            If N.Text = s Then
                N.Checked = True
            End If
            For Each node In N.Nodes
                CheckNode(node, s)
            Next
        End Sub
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        全選(或全不選)的方法:
         
                For i As Integer = 0 To ListView2.Items.Count - 1  '表格全選
                    ListView2.Items.Item(i).Checked = True
                Next
                For Each node As TreeNode In TreeView1.Nodes  '目錄樹全選
                    NodeAllCheck(node, True)
                Next
        Private Sub NodeAllCheck(ByVal N As TreeNode, checkinfo As Boolean)
            Dim node As TreeNode
            N.Checked = checkinfo
            For Each node In N.Nodes
                NodeAllCheck(node, checkinfo)
            Next
        End Sub
        ————————————————
        版權聲明:本文為CSDN博主「xjnzhidao」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
        原文鏈接:https://blog.csdn.net/xjnzhidao/article/details/47341387
        相關教程
                
        免费看成年人视频大全_免费看成年人视频在线观看