Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview with MANY nodes.

Status
Not open for further replies.

ponderdj

MIS
Dec 10, 2004
135
US
Hi,

I have a form that contains a treeview. The treeview has 3 levels, and I have buttons on the form that will rearrange the levels of the treeview if the user wants to. The treeview is populated with about 10,000 records on open... it doesn't take that long. However, when the user clicks a button to reorder the treeview, it clears the nodes and loops through the load_tree function (just as it does when the form loads), but this time is fed different parameters. This takes A LONG TIME, and I can see the treeview flashing as if it is redrawing itself each time it adds a node. I tried doing .visible = false, and then populating the treview and doing .visible = true at the end, but with the treeview set to not visible, access throws a memory exception error at the add node line.
Code:
Set nodCurrent = objTree.Nodes.Add(, , , Nz(xVar1, "-"))
So, I'd like to know. Is there a way to avoid redrawing the treeview everytime it adds a node? I think this will cause it to function just like it does on form open, which is much quicker.

Thanks
 
As as update, I found this:
I have used it to successfully clear the nodes, and it works great. I tried to use it to turn off redrawing before I add the nodes, then turn it back on afterwards, but had no luck.

The code I used is as follows:
Code:
Option Compare Database

Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd _
    As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Const TV_FIRST As Long = &H1100
Const TVM_GETNEXTITEM As Long = (TV_FIRST + 10)
Const TVM_DELETEITEM As Long = (TV_FIRST + 1)
Const TVGN_ROOT As Long = &H0
Const WM_SETREDRAW As Long = &HB
This works when I call it, stops redrawing, and clears the nodes quickly:
Code:
Public Sub ClearTreeView(ByVal tvHwnd As Long)
Dim lNodeHandle As Long

    'Turn off redrawing on the Treeview for more speed 
improvements 
    SendMessageLong tvHwnd, WM_SETREDRAW, False, 0

    Do
        lNodeHandle = SendMessageLong(tvHwnd, TVM_GETNEXTITEM, TVGN_ROOT, 0)
         If lNodeHandle > 0 Then
            SendMessageLong tvHwnd, TVM_DELETEITEM, 0, lNodeHandle
         Else
            Exit Do
         End If
    Loop

    'Turn on redrawing on the Treeview
    SendMessageLong tvHwnd, WM_SETREDRAW, True, 0
End Sub
This works, but does not stop redrawing and takes too long.
Code:
Public Sub Load_Tree(rst As Recordset, xVar1, xVar2, xVar3 As Variant)
Dim fld As dao.Field
Dim nodCurrent As Node
Dim nodCurrent_b As Node
Dim nodCurrent_c As Node
Dim objTree As TreeView
Dim strText As String
Dim strText2 As String
Dim tvHwnd As Long


'Let make sure we're at the beginning of the recordset
'If rst.EOF Then Exit Sub
rst.MoveFirst

'Set tvHwnd
tvHwnd = Form_FRM_PDC_DRILLDOWN.xTree.hwnd

'Turn off redrawing on the Treeview for more speed improvements---*This seems to not work*---
SendMessageLong tvHwnd, WM_SETREDRAW, False, 0

'Populate the treeview
'-----------------------------------------------------------------------'
Do Until rst.EOF = True
    On Error Resume Next
    If strText = Nz(xVar1, "-") Then GoTo skip
    Set nodCurrent = objTree.Nodes.Add(, , , Nz(xVar1, "-"))
    'Set the tag of the node to the field name and level.
    nodCurrent.Tag = xVar1.Name
    strText = Nz(xVar1, "-")

skip:
    If strText2 = Nz(xVar2, "-") Then GoTo skip2
    Set nodCurrent_b = objTree.Nodes.Add(nodCurrent, tvwChild, , Nz(xVar2, "-"))
    'Set the tag of the node to the field name.
    nodCurrent_b.Tag = xVar2.Name
    strText2 = Nz(xVar2, "-")

skip2:
    For Each fld In rst.Fields
        If fld.Name = xVar3 Then
            Set nodCurrent_c = objTree.Nodes.Add(nodCurrent_b, tvwChild, , Nz(rst(xVar3), "-"))
            'Set the tag of the node to the field name.
            nodCurrent_c.Tag = xVar3
        End If
    Next fld
    rst.MoveNext
Loop
'---------------------------------------------------------------------------'

'Turn on redrawing on the Treeview
SendMessageLong tvHwnd, WM_SETREDRAW, True, 0


'Clear everything
Set rst = Nothing
Set fld = Nothing
Set xVar1 = Nothing
Set xVar2 = Nothing
Set xVar3 = Nothing
Set objTree = Nothing
Set nodCurrent = Nothing
Set nodCurrent_b = Nothing
Set nodCurrent_c = Nothing

End Sub

Any help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top