Dumbo
Dumbo

Reputation: 14142

Preventing a TreeView from changing SelectedNode until a ListView getting populated

I have a TreeView and a ListView in my winforms application. The problem is when user selects a node from the treeview, it will take a while for a listview to get populated (Due to heavy calculations!).

Now I want to prevent any node to be selected unless the listview has been populated. The reason is if you keep selecting the nodes very fast using mouse or by tapping or holding down arrow key, the list is not getting populated. since this is for a monitoring of data usage, I want to prevent this behaviour. What are the avilable options to do such thing?

Upvotes: 0

Views: 781

Answers (1)

Kenny Louie
Kenny Louie

Reputation: 26

You could use a flag to track your ListView populating status and use the BeforeSelect event of the TreeView. If your ListView is still being populated have the BeforeSelect event handler cancel the event:

    private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
    {
        if (_loading)
            e.Cancel = true; 
    }

    bool _loading = false; 
    void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {
        _loading = true;
        // ListView populating
        _loading = false; 
    }

Upvotes: 1

Related Questions