views:

244

answers:

1

I have a WinForms TreeView. The TreeView represents a summary of more detailed views and one of the visual cues I am using is to make a node's text bold or regular. The trouble is, if you change a node's font from regular to bold it clips the text as if it is trying to fit the bold text in the space for the regular text.

A bit of browsing around shows that the usual workaround is to set the TreeView's font to the bold font, and selectively set nodes to regular.

This does work better, but once I have changed a node to regular, if I then change it back to bold it gets clipped again. Since I'm dynamically updating my view I'm hitting this problem.

Surprisingly I couldn't find any references to this issue on Stackoverflow, so thought I'd do my bit and float it here now. Does anyone know of a more thorough (but preferably not too overcomplex) workaround or solution to this issue?

I'm using C# 3 running on .Net 2.0, but can use .Net 3.5 if necessary.

[update]

No takers eh? That sucks. The best I have come up with myself so far is to add a load of spaces to the end of the string (to give it room to grow). That smells on so many levels (not least because it affects the scrollbars). I don't want to have to go for a third party control (or write my own) because this is just for an internal app for my dev team. Considering changing the metaphor, but it's a good fit.

+2  A: 

Hi Phil, I ran into the same problem with VB.Net and the solution was to call the following:

TreeView.BeginUpdate() '-- Poupulate your tree nodes here. TreeView.EndUpdate()

Edhy
Thanks Edhy. This sounded obvious - yet when I went to check my code - where I'm making the text bold it was within a `Suspend/ResumeLayout()`, but not `Begin/EndUpdate()`! Fixing that made the problem go away. I think I got too distracted by the fact that everywhere I searched I found the same problem reported, with no solutions offered, and even Microsoft conceding that it was a bug! Hopefully this post will help others to avoid the same mistake now :-)
Phil Nash