Sunday, 29 September 2013

VB.NET (VS2012) Treeview owner draw example from MS - odd behaviour

VB.NET (VS2012) Treeview owner draw example from MS - odd behaviour

I have a need to provide the count of items within a treeview folder after
the folder name, like Outlook does. ie: Inbox (134)
I found an example of the code I was looking for in the following
Microsoft Developer Network article.
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.drawnode.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
There is at least one issue with this code, and a second I have
encountered from the parts of the code I have extracted for my own use.
The first issue with the code itself is when you do not load the treeview
with all nodes expanded (comment out ExpandAll line). When you expand the
node (Task 3 in the example) that contains a subnode with the additional
ownerdraw field to appear after the node, that text also appears after the
root node (Task 1 in the example). But this only happens the first time.
If you now click Task 1, the additional data disappears from next to it
and you cannot reproduce this behaviour unless you restart the code.
Secondly, and this is not possible to show with the example as it is the
only control on the form, is when the treeview control loses focus.
When the treeview control loses focus, the ownerdrawn part of the node
becomes bold. There is no reference to bold anywhere in the code. When you
reselect the same node in the treeview the text stays bold, but if you
then select another node, the bold disappears.
This behaviour doesnt occur while the treeview remains in focus, you can
select whatever nodes you like and the ownerdrawn section behaves as it
should (not change to bold).
It looks to me that the code is incomplete somehow but I dont know enough
about ownerdraw coding at this stage to work out what is required.
Any help would be greatly appreciated.
Regards
Greg J

No comments:

Post a Comment