Avatar of canuckconsulting
canuckconsultingFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Need to bold selected node in Windows Forms TreeView control

I have a Windows Forms project using Visual Studio 2010 with c# and .Net 4.,

When selecting a node on a TreeView control I want the text to be bold.  Similarly when another node is selected the newly selected node should have its text in bold while the previous node is no longer in bold.
.NET ProgrammingC#

Avatar of undefined
Last Comment
canuckconsulting
ASKER CERTIFIED SOLUTION
Avatar of Navneet Hegde
Navneet Hegde
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of canuckconsulting

ASKER

This looks like it would work but in the end I created a custom control inheriting from TreeView and overrode the after select event as follows:

 
protected override void OnAfterSelect(TreeViewEventArgs e)
        {
            if (lastSelectedNode != null)
                lastSelectedNode.NodeFont = new Font(this.Font, FontStyle.Regular);

            if (SelectedNode != null)
                SelectedNode.NodeFont = new Font(this.Font, FontStyle.Bold);

            SelectedNode.Text = SelectedNode.Text; //Hack due to node not displaying all text correctly
            lastSelectedNode = SelectedNode;

            base.OnAfterSelect(e);
        }

Open in new window

Avatar of canuckconsulting

ASKER

Good advice for drawing but for simple bold I think a custom control was more straight forward.  \
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo