Quickly moving through a treeview causing crashes.

Posted on 2005-04-22
Last Modified: 2010-04-05
Been a while since I asked a question, but I wanted to get some thoughts on the best way to handle this scenario.

I have a standard treeview which gets populated at runtime, and then depending on what node you select, it goes to the database to get quite a bit of information each time to populate some frames.

The issue I am having, which I doubt is uncommon, is that if you move up and down the treeview fast using the mouse, the application crashes because it hasnt finished getting the previous information requested at the same time I am asking it to get the next nodes information etc.

What is the best way to handle this? Best way to almost halt the application while it retrieves the data it was asked for, then allow the user to move node again etc etc

Cheers fellow experts
Question by:mikelittlewood
    LVL 27

    Assisted Solution

    what about to disable the tree temporary and enable after the db.load is ready?
    LVL 15

    Author Comment

    Yeah I was wondering if it might be as simple as that, but was also wondering if there was an elegant way to do it.

    Currently using the OnChange I set a flag called bMoving to True and then at the end of the OnChange event Im setting it to false.
    Then on the OnChanging event Im doing AllowChange := not bMoving so that if it is already trying to do something it wont let the user change node.
    Hopefully this is the easiest way to handle the scenario.

    Ill hold on and see if anyone else comes up with another suggestion.
    LVL 11

    Accepted Solution

    Another way that works with DB Searches as well is to kick of a timer on the ONChange event. The timer only needs to be set to 500msecs

    So you get lv.OnChange
    //this resets the timer value to 500

    then in the OnTimer event add the codefor the rest of the work.

    This has the effect that if someone just holds down the up or down key then the timer keeps getting reset until the user stops and then the screen updates with the rest.

    This works well, I know I've used it thousands of times. but, and ofcouse theres always a but you still need to watch out for the timer firing twice.

    What you can do is to have a global Cancel flag and at regular intervals in your main update code check that flag and bail out if neccessary

    LVL 15

    Author Comment

    Thanks for the suggestion pcsentinel.
    LVL 14

    Assisted Solution

    or you can have a look at virtualtreeview ... been using that for some time, and haven't had such prob...
    LVL 15

    Author Comment

    Cheers for the advice all .. Ill give everyone a share of the points for the info

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now