treeview with lots of nodes (chapter 2)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

OK. My treeview still has a tier with too many nodes (ca. 20,000), but it's the best I can do. Now it only populates that tier in the (unlikely) event that a user tries to expand that tier's parent node.

To prevent the user from thinking its machine has locked up, I want to provide it with a progress bar to show that the nodes are being loaded. For generality, I created a form with a Label and a ProgressBar on it, but it doesn't really work like I want. I suspect I need to multithread, but I don't know how to do this, so...

Anyway, here's the code, any advice?

Private Sub LoadNonItemedFacilities(ByRef aNode As TreeViewEx.vb.TreeViewEx.TreeNode)
Dim drarray() As Data.DataRow
Dim dr As Data.DataRow
Dim filter As String = "Items Is Null"
Dim sort As String = "FDEPFacilityID"
Dim fac As Facility
Dim ndNew As TreeViewEx.vb.TreeViewEx.TreeNode
Dim cnt As Integer = 1
Dim recCount As Integer
Dim prg As frmProgress

drarray = dsFacilityInformation.tblFacility.Select(filter, sort, DataViewRowState.CurrentRows)
prg = New frmProgress
prg.Visible = True
prg.Text = "Populating Tree"
recCount = drarray.Length
prg.MaxValue = recCount
If Not drarray.Length = 0 Then
aNode.Nodes.Clear()
For Each dr In drarray
prg.Value = 100 * (cnt / recCount)
fac = New Facility(dr)
ndNew = New TreeViewEx.vb.TreeViewEx.TreeNode(fac.ToString)
ndNew.NodeKey = "fac" & fac.FDEPFacilityID
aNode.Nodes.Add(ndNew)
cnt = cnt + 1
Next
ndNew = New TreeViewEx.vb.TreeViewEx.TreeNode("<New>")
ndNew.NodeKey = "fac<New>"
aNode.Nodes.Add(ndNew)
End If
_nonItemedFacilitiesLoaded = True
prg.Close()

End Sub
 
pmcguire said:
OK. My treeview still has a tier with too many nodes (ca. 20,000), but
it's the best I can do. Now it only populates that tier in the (unlikely)
event that a user tries to expand that tier's parent node.
To prevent the user from thinking its machine has locked up, I want to
provide it with a progress bar to show that the nodes are being loaded. For
generality, I created a form with a Label and a ProgressBar on it, but it
doesn't really work like I want. I suspect I need to multithread, but I
don't know how to do this, so...
Anyway, here's the code, any advice?

Take a look at the ThreadPool documentation. It allows you to spawn a new
thread and pass it some data _very_ easily. So you code will look something
like this:

'// going from memory here,
'// so actual code may be slightly different
ThreadPool.QueNewWorkerThread(AddressOf LoadNonItemedFacilities,
THE_NODE_TO_LOAD)

and you will need to modify the signature of LoadNonItemedFacilities():

FROM:
Private Sub LoadNonItemedFacilities(ByRef aNode As
TreeViewEx.vb.TreeViewEx.TreeNode)

TO:
Private Sub LoadNonItemedFacilities(ByRef aNode As Object)
Dim targetNode as TreeViewEx.vb.TreeViewEx.TreeNode
targetNode = DirectCast(aNode, TreeViewEx.vb.TreeViewEx.TreeNode)
...


HTH,
Jeremy
 
Back
Top