Solved Expand TreeView at first child level

Posted on 2012-04-07
Last Modified: 2012-06-22
Hi. I am using the code below to fill a TreeView. What code would I use
to expand it only at the first child level as shown in the image
1Sub A()
        Dim xml_doc As New XmlDocument
        Dim xml_node As XmlNode
        Dim i As Integer
        Dim oCount As Integer = 0
        Dim arrKEY(10000) As String
        Dim arrDescription(10000) As String
        Dim arrParent(10000) As String
        Dim arrFolderOrReport(10000) As String
        Dim arrImage(10000) As String
        Dim oArrayIndex As Integer = -1
        Dim pCount As Integer = 0

        xml_node = xml_doc.DocumentElement

        For Each child_node As XmlNode In xml_node.ChildNodes

            oCount = oCount + 1
            arrKEY(oCount) = child_node.Attributes.GetNamedItem("key").InnerText
            arrFolderOrReport(oCount) = child_node.Name  'FOLDER or REPORT
            For i = 0 To child_node.ChildNodes.Count - 1
                If child_node.ChildNodes(i).Name = "DESCRIPTION" Then
                    arrDescription(oCount) = child_node.ChildNodes(i).InnerText
                ElseIf child_node.ChildNodes(i).Name = "PARENT" Then
                    arrParent(oCount) = child_node.ChildNodes(i).InnerText
                ElseIf child_node.ChildNodes(i).Name = "IMAGE" Then
                    arrImage(oCount) = child_node.ChildNodes(i).InnerText
                End If

        Next child_node


        For g = 0 To oCount

            Dim tns() As TreeNode
            If arrKEY(g) = "" Or arrKEY(g) = Nothing Or arrKEY(g) = "-- Bottom Row --" Then GoTo Jump
            If arrParent(g) = "" Then
                TreeView1.Nodes.Add(arrKEY(g), arrDescription(g))

                tns = TreeView1.Nodes.Find(arrParent(g), True)

                If tns.Length > 0 Then
                    tns(0).Nodes.Add(arrKEY(g), arrDescription(g))
                    MessageBox.Show("Parent Node Not Found")
                End If
            End If



        TreeView1.CheckBoxes = True

    End Sub
Question by:murbro
LVL 83

Accepted Solution

CodeCruiser earned 500 total points
ID: 37819665

LVL 20

Expert Comment

ID: 37819677
For Each tn As TreeNode In treeView1.Nodes
	If tn.Level = 1 Then
	End If

Open in new window


Author Closing Comment

ID: 37821673

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tabcontrol Caption? 1 29
Format column on datatable 7 28
Visual Studio .Net 2012 and Crystal Reports 9 45
VB.Net - Windows UserName index and length error 4 20
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

19 Experts available now in Live!

Get 1:1 Help Now