Community discussion forum

Help Me! About Treeview Control In VB.NET

  • 2 months ago

    How can I Collect all the Checked Child Nodes Name From a TreeView Control Using VB.NET. Thanks In Advanced.

    Post was edited on 14/09/2009 07:50:38 Report abuse
  • 2 months ago

    Dim i As Integer

    For i=0 to TreeView1.CheckedNodes.Count-1

     Dim tn As New TreeNode()
    
      tn = TreeView1.CheckedNodes.Item(0)
    
      Dim intvalue As Integer = tn.Value
    

    Next i

    By Above loop u can get the value of checked node in tn.value and collect in string or anything you want..

    Please reply if you get satisfied... Cheers...!!!!

  • 2 months ago

    Many many Thanks for ur code. But Its not working in VB.NET. Is it VB6 Code ?

    Actually

    Treeview1.CheckedNodes Not working.

    There are no Property named CheckNodes with TreeView Control. Thanks.

  • 2 months ago

    No popel its VB.Net Code only ....u might be missing something... Treview is having property Checkednodes in .Net

  • 2 months ago

    I have Just Placed a Treeview Control ( Named Treeview1) and a Command Button on my Form. In Command Button Click Event I have paste your code.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer

        For i = 0 To TreeView1.CheckedNodes.Count - 1
    
            Dim tn As New TreeNode()
    
            tn = TreeView1.CheckedNodes.Item(0)
    
            Dim intvalue As Integer = tn.Value
    
        Next i
    End Sub
    

    Error is : Error 1 'CheckedNodes' is not a member of 'System.Windows.Forms.TreeView'. E:\SSC Practise\TestSsc\TestSsc\Form1.vb 99 22 TestSsc

    What should I Do?

    Popel

  • 2 months ago

    well by the error and code it seems the u are working on windows application ...and the code i have given is for Web Application...

    Anyways i didnt worked in windows but i think u might go through all the properties u might get someway to get the required thing...

    just check weather you have selected node property by this you can check weather selected node is checked or not....

    TreeView1.SelectedNode.Checked = True

  • 2 months ago

    Thanks For all. Can any one help me Plz.

  • 1 month ago

    Well........... at last the problem solved.

    here is the code........

    .......................... ........................

    Private Function GetCheckedChildNodes(ByVal nodes As TreeNodeCollection) As TreeNode() Dim checkedNodes As New List(Of TreeNode)

    For Each node As TreeNode In nodes
        If node.Checked AndAlso node.Level > 0 Then
            checkedNodes.Add(node)
        End If
    
        checkedNodes.AddRange(Me.GetCheckedChildNodes(node.Nodes))
    Next
    
    Return checkedNodes.ToArray()
    

    End Function

    ......................... .........................

    Private Sub Button1_Click() Handles Button1.Click For Each node In Me.GetCheckedChildNodes(Me.TreeView1.Nodes) Console.WriteLine(node.FullPath) Next End Sub

    Thanks to all.

    Popel

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback