Solved

VB.net Expand TreeView at first child level

Posted on 2012-04-07
3
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to make search between pages 17 59
Vb.net progressbar with timer1 in visual studio win app 11 50
Best book for Internet security 4 55
Make borderless form movable by user 2 27
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

751 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