Solved

Need to bold selected node in Windows Forms TreeView control

Posted on 2011-09-08
3
581 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:canuckconsulting
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
navneethegde earned 500 total points
Comment Utility
Hi!

Check if this helps

http://www.longhorncorner.com/Forums/Thread/82383/

Thanks!
0
 

Author Comment

by:canuckconsulting
Comment Utility
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

0
 

Author Closing Comment

by:canuckconsulting
Comment Utility
Good advice for drawing but for simple bold I think a custom control was more straight forward.  \
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now