VB中使用TreeView生成了一个树状结构的表,然后选中某些节点前面的CheckBox(也就是打勾),表示想要删除的,请问代码如何实现?

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim nodex As Node
        Dim i As Integer
        Dim iCount As Integer
        
        iCount = TreeView1.Nodes.Count
        
        For i = iCount To 1 Step -1
            If TreeView1.Nodes(i).Checked = True Then
                TreeView1.Nodes.Remove TreeView1.Nodes(i).Index
            End If
        Next
    End SubPrivate Sub Form_Load()
        Dim Root As Node
        
        With TreeView1.Nodes
            Set Root = .Add(, , , "$1")
            .Add Root.Index, tvwChild, , "#1"
            .Add Root.Index, tvwChild, , "#2"
            .Add Root.Index, tvwChild, , "#3"
            Set Root = .Add(, , , "$2")
            .Add Root.Index, tvwChild, , "#1"
            .Add Root.Index, tvwChild, , "#2"
            .Add Root.Index, tvwChild, , "#3"
            Set Root = .Add(, , , "$3")
            .Add Root.Index, tvwChild, , "#1"
            .Add Root.Index, tvwChild, , "#2"
            .Add Root.Index, tvwChild, , "#3"
            Set Root = .Add(, , , "$4")
            .Add Root.Index, tvwChild, , "#1"
            .Add Root.Index, tvwChild, , "#2"
            .Add Root.Index, tvwChild, , "#3"
        End With
        
    End Sub