Help Me! About Treeview Control In VB.NET

VB.NET , DESKTOP APPLICATION , TREEVIEW CONTROL Ţungī, Bangladesh
  • 8 years ago

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

  • 8 years 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...!!!!

  • 8 years 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.

  • 8 years ago

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

  • 8 years 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

  • 8 years 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

  • 8 years ago

    Thanks For all. Can any one help me Plz.

  • 8 years 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).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare