开发者

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 r开发者_开发问答each 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜