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.
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.
链接地址: http://www.djcxy.com/p/52790.html下一篇: Vb.Net中的进度条和XML