Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

TreeView Text Width Calculation Bug

Skip to first unread message

Bill Henning

Jan 25, 2002, 3:21:42 PM1/25/02
If I have a TreeView and fill it with nodes and then decide to change one of
the node's font styles to bold, the end of the text in that node gets
chopped off. It seems like the TreeView isn't taking the NodeFont's style
into account when calculating the width of the text. Here's the code to
make it happen on a node named treeNode in a TreeView named treeView:

treeNode.NodeFont = new Font(treeView.Font, FontStyle.Bold);

In this example, making the font bolder widens the text but the TreeView
doesn't adjust for this. I am using RTM by the way.

Bill Henning
Actipro Software LLC

Check out our .NET components at:

Jacob Grass (MVP)

Jan 25, 2002, 3:51:22 PM1/25/02
This is an old issue with the TreeView. The Platform SDK says the

"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."

And, the docs say the following:

"If the node font is larger than the Font property value set in the TreeView
control, the tree node label text is clipped."

A way around this is to set the Font of the treeview to be bolded and then
unbold the nodes you don't want bolded. . .

Jacob Grass
Microsoft .NET MVP

"Bill Henning" <> wrote in message

Nathan Alden

Jan 26, 2002, 1:32:29 PM1/26/02
You'd think Microsoft would fix these stupid little bugs by now. Sometimes
the littlest bugs are the most annoying.


"Jacob Grass (MVP)" <> wrote in message

0 new messages