TreeView Flickering Problem
Anyone know how I can get rid of the annoying flickering that happens when my code updates the nodes.Text frequently?
I've tried BeginUpdate (Change) EndUpdate, I've tired Refresh(), etc. Nothing I can find that eliminates the flickering!
Thanks,
- J
[283 byte] By [
Mongoose] at [2007-11-17 12:50:28]

# 1 Re: TreeView Flickering Problem
This will cure your flicker, not the most elegant solution, but it works nicely. You will have to change your TreeView instance to use the derived class bellow. The code should be self explanatory if you take a look at WM_ERASEBKGND in MSDN.
internal class FlickerFreeTreeView : TreeView
{
public FlickerFreeTreeView()
: base()
{
}
private const int WM_ERASEBKGND = 0x0014;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_ERASEBKGND)
{
m.Result = IntPtr.Zero;
return;
}
base.WndProc(ref m);
}
}
# 2 Re: TreeView Flickering Problem
Thanks for the code. I have one question though. I know how to change my current tree view control to look at the new one.. but it screwed up my GUI. The tree view won't show up on the form. Is there a proper way to do this so you can resize, etc on the GUI?
Thanks,
- J
# 3 Re: TreeView Flickering Problem
Yes,
Put it into its own .cs file, and in your form make sure to qualify the control class name with the namespace, both on the declaration and when it is initialized. No troubles here.
Regards
# 4 Re: TreeView Flickering Problem
In addition,
If you want to get even more integrated, you can put the class in a library, declare it public, build the library and add it to the designer toolbox (via. The customize option) so it can be picked off the tool-palette and dropped on the form directly.
Regards
# 5 Re: TreeView Flickering Problem
[QUOTE]Originally posted by nvannote
This will cure your flicker [...]
I am also very grateful for your code. Although in my case it
did not remove the flicker completely, the improvement is
unexpectedly good.
I say unexpectedly because I tried other tricks - like
Invalidate/Update - and got no effect.
I am going to try it to list views ;)
Petru
# 6 Re: TreeView Flickering Problem
i think u r right. i had this prob. to ..
may be u can try listview..
PAresh
# 7 Re: TreeView Flickering Problem
Hi all,
Finally I have - thanks to Giovanni Montrone - a solution that
works satisfactory. There is a demo project that you can download
from:
http://www.codeproject.com/useritems/ListViewFF.asp?df=100&forumid=14314&select=422123
which solves precisely this problem. It seems, though, that indeed
the pair Invalidate/Update does not have the desired effect, so
one must use the WndProc approach.
In addition to the code in the second message of this
thread, a Validate for the big rectangle of the parent control
(ListView/TreeView) is required. With this adjustment, for me
the list view handled items refresh without any flicker.
The flicker-free tree view is easy to build using the patern
from the flicker-free list view.
Have fun!
Petru
# 8 Re: TreeView Flickering Problem
heya, this example is very nice to flicker free . I admire for your post.
thanx
Paresh