Results 1 to 3 of 3

Thread: using check boxes with the treeview

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7

    using check boxes with the treeview

    Hi,

    I'm using a tree view control in VB.NET to display the directory structure across all my disk drives. This I have done successfully.

    Now, I'm also using check boxes on each node. The idea being that if I check one of the boxes then every check box lower down in the hierarchy will also be checked. This is where I'm stuck.

    How can I check every check box on each child node (and subsequent child node) when I check a parent node check box?

    I have tried using the BeforeCheck (or AfterCheck) event but the problem is that when I programmatically check the child node, this fires off the very same BeforeCheck event.

    Any ideas or suggestions as to how I can do this would be most welcome. Please bear in mind that my competence level with VB.NET is basic.

    Thanks,

    Karl

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    This worked for me:

    Code:
    Private Sub TreeView1_BeforeCheck(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeCheck
    
        If Not e.Node.Checked Then
            Dim node As TreeNode
            For Each node In e.Node.Nodes
                node.Checked = True
            Next
        Else
            Dim node As TreeNode
            For Each node In e.Node.Nodes
                node.Checked = False
            Next
        End If
    
    End Sub
    /Leyan

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    7

    Thumbs up thanks

    Thanks Leyan,

    that works perfectly.

    Karl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width