We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Different Colors in TreeView

Thread ID:

Created:

Updated:

Platform:

Replies:

34832 Sep 16,2005 10:56 AM Sep 19,2005 12:11 AM Windows Forms 1
loading
Tags: Tools
Vinay
Asked On September 16, 2005 10:56 AM

Hi All, Can we have different colors for different treeview nodes. For alternate nodes color should change. Thanks Vinay

Vijayanand S [Syncfusion]
Replied On September 19, 2005 12:11 AM

Hi Vinay, You could change different colors for different TreeViewAdv nodes by using the BeforeNodePaint event and setting the OwnerDrawNodes to true. Please take a look at the following code snippet and the attached test sample. private void treeViewAdv1_BeforeNodePaint(object sender, Syncfusion.Windows.Forms.Tools.TreeNodeAdvPaintEventArgs e) { SolidBrush brush = new SolidBrush(Color.LightSeaGreen); Rectangle rec = new Rectangle(e.Node.TextBounds.X, e.Node.TextBounds.Y, e.Node.TextBounds.Width, e.Node.TextBounds.Height); if(e.Node.Text=="Node1" || e.Node.Text=="Node4"||e.Node.Text=="Node7") { brush = new SolidBrush(Color.YellowGreen); rec = new Rectangle(e.Node.TextBounds.X, e.Node.TextBounds.Y, e.Node.TextBounds.Width, e.Node.TextBounds.Height); } if (e.Node.IsSelected == true) { brush = new SolidBrush(Color.Aqua); rec = new Rectangle(e.Node.TextBounds.X, e.Node.TextBounds.Y, e.Node.TextBounds.Width, e.Node.TextBounds.Height); } e.Graphics.FillRectangle(brush, rec); } Please let me know if you have any questions. Thanks for your patience. Regards, Vijay

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;