Murray Brown
asked on
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
Sub 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\use r\Document s\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.GetN amedItem(" key").Inne rText
arrFolderOrReport(oCount) = child_node.Name 'FOLDER or REPORT
For i = 0 To child_node.ChildNodes.Coun t - 1
If child_node.ChildNodes(i).N ame = "DESCRIPTION" Then
arrDescription(oCount) = child_node.ChildNodes(i).I nnerText
ElseIf child_node.ChildNodes(i).N ame = "PARENT" Then
arrParent(oCount) = child_node.ChildNodes(i).I nnerText
ElseIf child_node.ChildNodes(i).N ame = "IMAGE" Then
arrImage(oCount) = child_node.ChildNodes(i).I nnerText
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(arrPa rent(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
to expand it only at the first child level as shown in the image
Sub 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\use
xml_node = xml_doc.DocumentElement
For Each child_node As XmlNode In xml_node.ChildNodes
oCount = oCount + 1
arrKEY(oCount) = child_node.Attributes.GetN
arrFolderOrReport(oCount) = child_node.Name 'FOLDER or REPORT
For i = 0 To child_node.ChildNodes.Coun
If child_node.ChildNodes(i).N
arrDescription(oCount) = child_node.ChildNodes(i).I
ElseIf child_node.ChildNodes(i).N
arrParent(oCount) = child_node.ChildNodes(i).I
ElseIf child_node.ChildNodes(i).N
arrImage(oCount) = child_node.ChildNodes(i).I
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
Else
tns = TreeView1.Nodes.Find(arrPa
If tns.Length > 0 Then
tns(0).Nodes.Add(arrKEY(g)
Else
MessageBox.Show("Parent Node Not Found")
End If
End If
Jump:
Next
TreeView1.EndUpdate()
TreeView1.CheckBoxes = True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Open in new window