Solved

VB.net Expand TreeView at first child level

Posted on 2012-04-07
3
668 Views
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_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
Comment
Question by:murbro
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37819665
Try

Treeview1.Nodes(0).Expand()
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37819677
For Each tn As TreeNode In treeView1.Nodes
	If tn.Level = 1 Then
		tn.Expand()
	End If
Next

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 37821673
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

18 Experts available now in Live!

Get 1:1 Help Now