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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Control Problem 1

Status
Not open for further replies.

ddbbgg

Programmer
Oct 18, 2002
5
0
0
US
I am having a treeview control problem in access 2000. the treeview is located on the first page of a tab control and works fine as long as i remain on that page. as soon as i change to another page on the tab control, and come back, the nodes of the treeview are garbled. the next click i make on the form (no matter where i click) causes an msaccess.exe application error and results in access shuting down.

i noticed through debugging that the treeview expand event is the first event triggered (other than the tab control change event) when i come back to the page where the treeview resides.

anyone know why the treeview nodes would be garbled and cause msaccess to fail when changing pages on a tab control?

also, why is the expand event the first event trigged on re-entering the page?
 
You must be setting the Expanded property somewhere in your code or else it would not fire at all. Have you tried eliminating that call?

I put a basic treeview on a tabbed form and played with it and it works fine for me (Access 2000).

Are you using checkboxes in the treeview? If so check this article:


It says a GDI leak was fixed in SP4 - what SP are you running? (Mine is SP4) VBSlammer
redinvader3walking.gif
 
I am using SP4. through further debugging i have narrowed the problem down to the treeview expand event.

try this on the sample you created? for debugging purposes put simple msgboxes in the form load, open, activate, tree expand, and tab change envents. The msgbox should identify the event that is being triggered. open the form and follow the sequence of msgboxes making sure the events are triggering in the correct order.

what happens to me, is the treeview expand is firing off without being called. the first misfire is after form open, but before form activate.

the second misfire is when switching pages on the tab. when leaving the page where the treeview is everything is fine. when coming back, the expand event is called before the tab change event.

the misfires are causing a problem because the expand event code is being reexecuted, trying to refill the tree nodes each time. the misfire eventually eats up my resources and causes the msaccess.exe exception that closes the app down.

i tried unloading the control and form from memory using UNLOAD, but access responds with an error telling me the form cannot be unloaded.

this is all very strange, because everything works fine as long as i do not leave the page where the treeview is.
 
OK. Here is what I experienced upon further testing:

The expand event for the Treeview is automatically called when the tab page becomes visible. There is also a corresponding Collapse event for each node in the tree.

I tried taxing my example a little by adding 20000 nodes to the tree to see the impact, and it reloaded the tree every time I switched it back into view, which for 20000 nodes took over 10 seconds - Unacceptable.

So, that means 40000 events (collapse and re-expand for each node).

MSDN documentation states that ActiveX controls may not work the same in Access as they do in VB. Here, it appears that the Access Tab Control forces a reloading of the tree even if it is not warranted (i.e. its contents have changed).

As a workaround, I placed the Treeview control onto a blank form (no nav buttons | dividing lines | scroll bars | record selectors) and used it as a subform on the Tab Control page, and that solved the problem. No more expanding/collapsing between page changes.

I should note that I didn't experience any display anomalies like yours during testing but I can see how this continual loading of the treeview could deplete resources.

Solution:
Try putting the Treeview on a subform in the Tab Control.

Regards,

VBSlammer
redinvader3walking.gif
 
VBSlammer, I will try putting the treeview on a subform. thanks for your help!!

I am a little concerned though. i thought my treeview expand logic would stop the inappropriate reloading of the tree. Do i have something missing/incorrect with this logic?

Private Sub objTreeview1_Expand(ByVal Node As Object)
Dim objFormList As Control

'// Set object variable equal to Listview control. There is more than one listview in application. procedure that fills list needs to know which one to fill.
Set objFormList = Me.objListView1

'// Exit procedure if there are not any children or list of children is already filled
If Node.Children <> 1 Then Exit Sub

If Node.Child.Text <> FAKED_CHILD Then Exit Sub

'// Remove faked child and fill list with children
Me.objTreeview1.Nodes.Remove Node.Child.Index

'// Verify which node was expanded and get SQL needed to populate tree and fill specified listview
Call sVerifyNodeClick(Node, objFormList)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top