curiosity
curiosity

Reputation: 1233

How to avoid flickering in treeview

how to avoid flickering in treeview,

when some property of nodes is gettng updated, or the node is added

Upvotes: 2

Views: 7074

Answers (2)

chrismead
chrismead

Reputation: 2243

I was fighting this, too. Here is my solution for those of you searching out there. Add this to your treeview subclass.

    private const int WM_VSCROLL = 0x0115;
    private const int WM_HSCROLL = 0x0114;
    private const int SB_THUMBTRACK = 5;
    private const int SB_ENDSCROLL = 8;

    private const int skipMsgCount = 5;
    private int currentMsgCount;
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_VSCROLL || m.Msg == WM_HSCROLL)
        {

            var nfy = m.WParam.ToInt32() & 0xFFFF;
            if (nfy == SB_THUMBTRACK)
            {
                currentMsgCount++;
                if (currentMsgCount % skipMsgCount == 0)
                    base.WndProc(ref m);
                return;
            }
            if (nfy == SB_ENDSCROLL)
                currentMsgCount = 0;

            base.WndProc(ref m);
        }
        else
            base.WndProc(ref m);
    }

I got the idea here: treeview scrollbar event

Basically I am just ignoring a significant percentage of the scroll messages. It reduces flicker a lot for me.

Upvotes: 2

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29632

Try the following:

try
{
    treeView.BeginUpdate();

    // Update your tree view.
}
finally
{
    treeView.EndUpdate();
}

Upvotes: 6

Related Questions