Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 931
  • Last Modified:

VB.net Expand TreeView at first child level

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_doc.Load("C:\Users\user\Documents\REPORTS.xml")
        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

        Next child_node

        TreeView1.BeginUpdate()

        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))
            Else

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

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

Jump:
        Next

        TreeView1.EndUpdate()

        TreeView1.CheckBoxes = True

    End Sub
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
CodeCruiserCommented:
Try

Treeview1.Nodes(0).Expand()
0
 
BuggyCoderCommented:
For Each tn As TreeNode In treeView1.Nodes
	If tn.Level = 1 Then
		tn.Expand()
	End If
Next

Open in new window

0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now