Question

I am creating a custom winforms Treeview that is completely owner drawn. When a bolded text node is drawn and reaches beyond the width of the Treeview, the text is cutoff because the horizontal scrollbar cannot scroll any further. I assume it has something to do with the bold text and it can't figure out the correct width. Is there a way to correct the scrollbar, so that it can scroll all the way.

Was it helpful?

Solution

There is no clean fix for this, the native Windows treeview control is missing a "MeasureNode" kind of message. Which would be required to give the horizontal scrollbar the proper range if you custom-draw a wider string. So, inevitably, it is still based on the size of the TreeNode.Text string.

There's a dirty fix for this, it works but is unpleasant. You do it by giving the TreeNode.Text property a fake string, wide enough to whack the scrollbar in shape. And use, say, the Tag property to store the real string you want to draw. Ugly but effective hack. Unpleasant because you cannot easily hide that code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top