Is there any way to control the flicker that occurs when an idividual node's
BackColor property is changed in a treeview? It appears that the entire
control is invalidated and redrawn. How can I invalidate only the node that
has the background color changing?

Re: TreeView flicker on changing Node.BackColor by Frans

Frans
Tue Jun 28 02:58:52 CDT 2005

wgillin wrote:

> Is there any way to control the flicker that occurs when an idividual
> node's BackColor property is changed in a treeview? It appears that
> the entire control is invalidated and redrawn. How can I invalidate
> only the node that has the background color changing?

You could try
treeview.BeginEdit();
// your code here
treeview.EndEdit();

though I found this to look slower in many occasions, for the most
part because it won't show any changes until all edits are done, which
gives the feeling nothing happens, and with live updates it might
appear faster.

I just change the back color without begin/end edit and don't
experience flickering.

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Re: TreeView flicker on changing Node.BackColor by Frans

Frans
Tue Jun 28 03:08:45 CDT 2005

Frans Bouma [C# MVP] wrote:

> wgillin wrote:
>
> > Is there any way to control the flicker that occurs when an
> > idividual node's BackColor property is changed in a treeview? It
> > appears that the entire control is invalidated and redrawn. How
> > can I invalidate only the node that has the background color
> > changing?
>
> You could try
> treeview.BeginEdit();
> // your code here
> treeview.EndEdit();

This of course should have been BeginUpdate() and EndUpdate(). Sorry
for that :)

FB

Re: TreeView flicker on changing Node.BackColor by wgillin

wgillin
Tue Jun 28 07:06:02 CDT 2005

Thanks Frans. I tried this but the entire control is still invalidated. The
code I am using to toggle the background is:

this.FlaggedNode.BackColor = Color.FromName("Highlight");
this.FlaggedNode.ForeColor = Color.FromName("Window");

Where FlaggedNode is an extended property of the TreeView similar to
SelectedNode.

The method to change the color is only getting called once while the cursor
is over the FlaggedNode so it's not a bug with calling the method. For some
reason the entire control is invalidated rather than the node rect and I
can't figure out how to override this.

"Frans Bouma [C# MVP]" wrote:

> Frans Bouma [C# MVP] wrote:
>
> > wgillin wrote:
> >
> > > Is there any way to control the flicker that occurs when an
> > > idividual node's BackColor property is changed in a treeview? It
> > > appears that the entire control is invalidated and redrawn. How
> > > can I invalidate only the node that has the background color
> > > changing?
> >
> > You could try
> > treeview.BeginEdit();
> > // your code here
> > treeview.EndEdit();
>
> This of course should have been BeginUpdate() and EndUpdate(). Sorry
> for that :)
>
> FB
>

Re: TreeView flicker on changing Node.BackColor by Frans

Frans
Tue Jun 28 11:28:51 CDT 2005

wgillin wrote:

> Thanks Frans. I tried this but the entire control is still
> invalidated. The code I am using to toggle the background is:
>
> this.FlaggedNode.BackColor = Color.FromName("Highlight");
> this.FlaggedNode.ForeColor = Color.FromName("Window");
>
> Where FlaggedNode is an extended property of the TreeView similar to
> SelectedNode.
>
> The method to change the color is only getting called once while the
> cursor is over the FlaggedNode so it's not a bug with calling the
> method. For some reason the entire control is invalidated rather
> than the node rect and I can't figure out how to override this.

If FlaggedNode is just a TreeNode object, then I don't know what's
happening. I use the same code as you and no flickering.

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------