Solved

VB.net TreeView Gather checked nodes

Posted on 2014-12-28
2
699 Views
Last Modified: 2014-12-28
Hi

I have TreeView with the CheckBoxes property set to True
After the user has checked various nodes, what VB.net code
would I use to gather the text of only these checked nodes?
0
Comment
Question by:murbro
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
You need a recursive routine to traverse the nodes collections of the treeview and gather the checked nodes.

Here's one possibility:
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim checked As List(Of TreeNode) = GetCheckedNodes(TreeView1)
        For Each node As TreeNode In checked
            Debug.Print(node.FullPath)
        Next
    End Sub

    Private Function GetCheckedNodes(ByVal TV As TreeView) As List(Of TreeNode)
        Dim checked As New List(Of TreeNode)
        For Each node As TreeNode In TV.Nodes
            GetCheckedNodes(node, checked)
        Next
        Return checked
    End Function

    Private Sub GetCheckedNodes(ByVal tn As TreeNode, ByVal checked As List(Of TreeNode))
        If tn.Checked Then
            checked.Add(tn)
        End If
        For Each childNode As TreeNode In tn.Nodes
            GetCheckedNodes(childNode, checked)
        Next
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now