It is not possible to make a single node bold without the end of the node text being clipped. The work around this problem, I tried setting all nodes to bold and then setting all but one to regular. The problem now is that the selection box when selecting a non-bold node is too big!
This is quite a major problem as it means .NET developers cannot replicate the look and feel of the standard Windows treeview.
Is this a known issue and if so, when will it be fixed

Treeview Bug
Lei Jiang
For me the above code worked fine.
But i m facing the problem for the TreeNode Control.
For the TreeNode the the text of the node who are shown in bold color still shows me the Text Clipped.
Any Help in that direction
Thanks
Vikash
Ken Grissom
I've discovered that many other people have run into this frustrating limitation of the Windows Forms TreeView. It's even more frustrating because Microsoft claims this limitation is necessary for backwards compatibility (what a bunch of nonsense) and yet they turn right around and use treeviews in their software that behave like you would expect.
In researching this issue you're likely to stumble across the page on "Customizing a Control's Appearance Using Custom Draw (http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/custdraw/custdraw.asp) and particularly the section titled "Changing fonts and colors". This section gives an explanation for how to (one would think) overcome this difficulty with fonts by taking advantage of CustomDraw. But if you read further you'll notice a snide remark that states "For Version 5.0, these two controls may display clipped text if you change the font by returning CDRF_NEWFONT. This behavior is necessary for backward compatibility with earlier versions of the common controls."
The paragraph goes on to state that you can get around this ridiculous clipping behavior by sending a CCM_SETVERSION message to the control. However, it fails to give any example of how to accomplish this task. In fact, I noticed at least one developer had attempted to implement this suggestion and decided that it didn't work. When I gave it a shot, I came to the same conclusion at first. If you send this message from the constructor of a subclassed control as I was doing, for example, it really screws things up. Instead, it appears that if you're careful to send the message after the underlying handle has been created, things start looking up.
In the end, after writing hundreds of lines of code trying to get this working, I think have it mastered using just ten lines of code. And I didn't even have to use CustomDraw. As always, there's many ways this could be done, but here's one solution to this problem using a subclassed control. Simply compile these *ten* lines of code into a custom control (this exmaple is written in Visual Basic .NET but could easily be translated into C#) and use this new control rather than the broken version of the TreeView shipped with Windows Forms:
Public Class FixedTreeView
Inherits TreeView
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
Const CCM_FIRST As Integer = &H2000
Const CCM_SETVERSION As Integer = (CCM_FIRST + &H7)
Dim msg As Message = Message.Create(Me.Handle, _
CCM_SETVERSION, _
IntPtr.op_Explicit(5), _
IntPtr.op_Explicit(0))
DefWndProc(msg)
End Sub
End Class
Julian Price
Anyway... What I want to do with it is use a TreeView to show a hierarchy of reports, sections (header, footer, etc.), and fields -- the user can click on a field to set the Font and Color and I want the TreeNode text to reflect the selected Font (Color works fine of course). At this time I have to add the name and size of the Font to the text, e.g. "HeaderText -- Arial, 36pt", but I'd rather have the text rendered in the actual Font -- and not get clipped. So this would affect the NodeHeight as well.
Hamid H. Awan
I translated this code into C# but it doesn't work. When set font style to bold text is cliped. Could you help me
public class TreeViewFixedBoldFonts : TreeView
{
protected override void OnCreateControl()
{
base.OnCreateControl ();
const int CCM_FIRST = 0x2000;
const int CCM_SETVERSION = (CCM_FIRST + 0x0007);
Message msg = Message.Create(this.Handle,CCM_SETVERSION,new IntPtr(5), new IntPtr(0));
DefWndProc(ref msg);
}
}
MadhuSri
tn.NodeFont = new Font( this.Font.FontFamily, this.Font.Size, FontStyle.Bold );
// HACK: Makes the entire Node text display, more or less.
tn.Text = tn.Text + new String(' ', 10 );
//in other words, Just add a space to the end, trim when necessary
cro
How exactly do I "send a CCM_SETVERSION message with the wParam value set to 5" using VB.NET
Thanks.
Mubarak Sha
gift
Secrets
yulia_o
"For Version 5.0 of the common controls, these two controls may display clipped text if you change the font by returning CDRF_NEWFONT. This behavior is necessary for backward compatibility with earlier versions of the common controls. If you want to change the font of a list-view or tree-view control, you will get better results if you send a CCM_SETVERSION message with the wParam value set to 5 before adding any items to the control."
David T92166
Rick Boardman
www.netbotics.com
Gary Cabana
SSG31415926
So, yeah, this is weird and is a bug in that the selection rectangle doesn't resize based on the NodeFont.
As for sending the message, it's certainly doable, but you'll need to create a derived treeview and, unfortunately, it doesn't work... I just tried it with the following code:
Public Class MyTreeView
Inherits TreeView
Public Sub New()
MyBase.New()
Const CCM_SETVERSION As Integer = &H2000& + 7
Dim m As Message = Message.Create(Me.Handle, CCM_SETVERSION, IntPtr.op_Explicit(5), IntPtr.Zero)
WndProc(m)
End Sub
End Class
I am curious though...I'll play around when I have some time and see if I can come up with a workaround for you.
KeithGarrett
Are the .NET development team aware of this issue and, if so, do they plan to fix it in a future release