views:

548

answers:

1

We have some code that uses the .net Windows.Forms.TreeView. When an item in the view is selected then code does

treeView.BeginUpdate();
// ... some stuff ...
SendMessage(treeView.Handle, WM_HSCROLL, SB_LEFT, 0);
treeView.EndUpdate();

This is so that the tree view display doesn't scroll right (which is the default behaviour - to show as much of the selected item label as possible I assume but at the expense of hiding some of the tree structure). Unfortunately when the tree view contains 30,000 items and this code is called during a right-click and results in the context menu takes a couple of seconds to appear (enough to be disconcerting).

If you remove the Begin/EndUpdate, then the context menu appears instantly, but you get an annoying twitch as you see the view move right and then back the left edge. The suggestion of getting rid of the "push it back to the left edge" scroll is encountering some resistance.

I've tried filtering out SB_RIGHT on the tree view but that doesn't seem to actually be used to when the control moves to show the label.

So is there a way of keeping the tree view in at it's current horizontal scroll position when the item is selected that doesn't involve Begin/EndUpdate and the corresponding lag or the twitch?

A: 

Have you tried only populating nodes of the tree "on demand?"

This should result in fewer nodes in the tree and therefore faster processing of the BeginUpdate.

Jason D
Yes, we already do that.
Ian G
Interesting I'll have to see what a coworker of mine did. I know I've seen something similar in code at work. If I can dig up a working example with a similar tree node count I'll edit my reply and post it.
Jason D