Click here to Skip to main content
15,915,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
When the winform application loads first row's cell in treeview has blue backcolor.
How do I change the color of it?
Thank you in advance

What I have tried:

Afterselected event,Beforeselected event but it didn't work
Posted
Updated 22-May-16 17:52pm
Comments
PIEBALDconsult 22-May-16 22:30pm    
I think that "blue backcolor" is actually just the indication that the node is selected.
an0ther1 22-May-16 22:37pm    
PIEBALDconsult is correct.
This needs to be changed via the Windows Control Panel. It is the default for a selected item.
Open Control Panel got to Personalisation & select Window Color at the bottom of the screen.
In the "Item" field select the Item "Selected Item" and change color as required.
I am not sure if you can over-ride this

Kind Regards
hapiten 22-May-16 23:38pm    
Can I set not to show it when the treeview form loads?

1 solution

Try this
You have to Change the DrawMode from Normal to OwnerDrawText and Change the color in drawNode event

C#
private void Form1_Load(object sender, EventArgs e)
       {
           treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
       }


       SolidBrush greenBrush = new SolidBrush(Color.Green);

       private void treeView1_drawNode(object sender, DrawTreeNodeEventArgs e)
       {
           if (e.Node.IsSelected)
           {
               if (treeView1.Focused)
                   e.Graphics.FillRectangle(greenBrush, e.Bounds);
           }
           else
               e.Graphics.FillRectangle(Brushes.White, e.Bounds);

           TextRenderer.DrawText(e.Graphics,    e.Node.Text,  e.Node.TreeView.Font,  e.Node.Bounds,  e.Node.ForeColor);
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900