question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TreeView flickering

See original GitHub issue
  • .NET Core Version: all up to latest (5.0.5).

  • Have you experienced this same bug with .NET Framework?: yes

Problem description: TreeView is flickering (especially on large amount of data): Native control has ex. style TVS_EX_DOUBLEBUFFER that fix the problem:

private class TreeViewEx : TreeView
{
    private const int TVM_SETEXTENDEDSTYLE = 0x1100 + 44;
    private const int TVS_EX_DOUBLEBUFFER = 0x0004;

    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr SendMessage(IntPtr HWnd, int Msg, IntPtr Wp, IntPtr Lp);

    protected override void OnHandleCreated(EventArgs e)
    {
        SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_DOUBLEBUFFER, (IntPtr)TVS_EX_DOUBLEBUFFER);
        base.OnHandleCreated(e);
    }
}

Left default TreeView, Right with TVS_EX_DOUBLEBUFFER: TreeView stackoverflow.

Expected behavior: Ability to avoid flickering without Pinvoke and deriving own class from TreeView. P.s. protected DoubleBuffered doesn’t solve the problem. P.p.s. May be API request is more suitable here?

Minimal repro: TreeViewFlickering.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
KlausLoeffelmanncommented, May 12, 2021

A proposal it is.

2reactions
RussKiecommented, May 11, 2021

According to the docs DoubleBuffered=true makes no difference, though this would be the first thing I’d try. Perhaps this is something we could consider enhancing. @merriemcgaw @KlausLoeffelmann what do you think?

Also interestingly enough we have this method: https://github.com/dotnet/winforms/blob/d46ad2e8dc76248739d9ae22b28b399a6a6b299e/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/DesignerUtils.cs#L878-L892

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Treeview flickering?
Getting flicker at EndUpdate() is inevitable, it repaints the control. They were designed to speed-up adding a bulk of nodes, that will be...
Read more >
TreeView.DoubleBuffered Property (System.Windows.Forms)
Setting the DoubleBuffered property does not affect the TreeView control. If you want to reduce flicker when the TreeView is drawn, use the...
Read more >
Re: TreeView Flickering Problem
TreeView Flickering Problem. Anyone know how I can get rid of the annoying flickering that happens when my code updates the nodes.
Read more >
Prevent flickering when updating TreeView nodes
I'm working on an RSS reader in .NET 2.0. It's a WinForms app. Like most RSS readers, it's got an outlook-style layout with...
Read more >
TreeView flickering? - C# Discussion Boards
So, I've essentially implemented a folder browser with a TreeView, and what I'm doing is trying to get it to remove flickering. Here's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found