Grekoz
Grekoz

Reputation: 275

Progress bar and XML in Vb.Net

Does anyone here know how to integrate a progress bar while loading an xml data into a treeview in VB.Net? Most xml data I am loading can reach upto 30MB so the form freezes while the xml data is loaded or when the nodes are added in the treeview.

Here is the code for creating the nodes in the treeview:

Private Sub AddNodes(ByRef parent As TreeNodeCollection, ByVal root As XmlNode)
    For Each child As XmlNode In root.ChildNodes
        Dim newNode As TreeNode = parent.Add(child.Name)
        AddNodes(newNode.Nodes, child)
        newNode.Collapse()
    Next child    
End Sub

This is how I call the procedure:

Private Sub LoadXMLData(ByVal filname As String, ByRef trv As TreeView)
     Dim xmlData As New XmlDocument
     xmlData.Load(filename)
     trv.Nodes.Clear()
     AddNodes(trv.Nodes, xmlData.DocumentElement)
End Sub

Any help is appreciated. Thanks.

Upvotes: 0

Views: 508

Answers (1)

StingyJack
StingyJack

Reputation: 19489

Take a look at the Background Worker. That should let you report loading progress, and when complete display the tree.

You will have to do some refactoring (move some members to Private instead of locals), but it should do the trick.

Upvotes: 2

Related Questions