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. Image for the cookie policy date
close icon

Different Colors in TreeView

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

1 Reply

VS Vijayanand S Syncfusion Team September 19, 2005 04:11 AM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon