Re: Bug in TreeView control
- From: Korey Mateer <KoreyMateer@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 2 Aug 2007 21:34:00 -0700
"MikeD" wrote:
It's not a bug in the control, but rather a "bug" in VB's documentation for
the control. To have the +/- buttons, you must also have treelines. If you
take a look at the Platform SDK docs
(http://msdn2.microsoft.com/en-us/library/ms650019.aspx) for a TreeView, it
states the following:
--
TVS_HASBUTTONS
Displays plus (+) and minus (-) buttons next to parent items. The user
clicks the buttons to expand or collapse a parent item's list of child
items. To include buttons with items at the root of the tree view,
TVS_LINESATROOT must also be specified.
TVS_LINESATROOT
Uses lines to link items at the root of the tree-view control. This value is
ignored if TVS_HASLINES is not also specified.
TVS_HASLINES
Uses lines to show the hierarchy of items.
--
To see that the above is indeed correct, try this code (with Style = 3;
LineStyle is ignored with this particular Style setting):
Private Sub Form_Load()
TreeView1.Nodes.Add , , "N1", "Node 1"
TreeView1.Nodes.Add , , "N2", "Node 2"
TreeView1.Nodes.Add , , "N3", "Node 3"
TreeView1.Nodes.Add "N1", tvwChild, "N4", "Node 4"
TreeView1.Nodes.Add "N1", tvwChild, "N5", "Node 5"
TreeView1.Nodes.Add "N2", tvwChild, "N6", "Node 6"
TreeView1.Nodes.Add "N6", tvwChild, "N7", "Node 7"
End Sub
If you expand Node 2, you'll see a + button for Node 6 because that node has
a child node (Node 7) of its own. Note, however, that unless you have tree
lines to show the hierarchy, the + button is left-justified rather than
right beside the node. IOW, the control is functioning exactly as the SDK
docs describe. It's VB's docs that are misleading/wrong/incomplete.
IMO however, the easist thing for you to do is just set LineStyle = 1 and
Style = 7.
--
Mike
Microsoft MVP Visual Basic
Thank you very much Mike for your assistance. It seems that you are correct
but I'd still like to address this issue.
I have found no inconsistencies in the Visual Basic or Platform SDK
documentation. The problem I realize, is the logic in architecture of the
treeview control, which I believe to be inconsistent and will explain.
When setting the Style property to 3 - tvwPlusPictureText will display, the
treeview control will display, WITHOUT root or tree lines, a plus\minus box,
picture and text, on every level of the hierarchy EXCEPT the root.
Your sample program perfectly demonstrates this behavior: Node 6 has a
picture (I use a folder icon), text and a plus\minus box signifying it has a
child node. Note that Node 6 is itself a second level node. Now Node 1 has
two children but since Node 1 is a root level node it does not have a
plus\minus box according to the TVS_HASBUTTONS setting specified in the SDK.
Although this behavior does coincide with the Platform SDK, it is not
consistent.
Why is the plus\minus box dependent on root lines? The treeview control can
display, WITHOUT root or tree lines, the plus\minus box on every level except
the root. To get the plus\minus box on the root level, root and tree lines
HAVE to be added! How can this be deemed consistent? Holy cow!
Setting the LineStyle property to 1 - tvwRootLines and the Style property to
7 - tvwTreelinesPlusMinusPictureText as you suggested works great but, as you
probably know, the control also displays root and tree lines. I want neither.
I will greatly simplify this problem with a single request: I would like to
display the plus\minus box on the ROOT level WITHOUT root lines. It is not
possible using any combination of the Style and LineStyle property settings.
I can't believe this feature was not included or intended to be part of the
treeview's general architecture. If it is deemed consistent then I strongly
recommend for any future version of the treeview control to include the
option to simply display a plus\minus box on the root level WITHOUT the need
to add root or tree lines.
Thanks again for your time and consideration.
-Korey Mateer
.
- Follow-Ups:
- Re: Bug in TreeView control
- From: Mark J. McGinty
- Re: Bug in TreeView control
- From: Timo Kunze
- Re: Bug in TreeView control
- From: Michael Cole
- Re: Bug in TreeView control
- References:
- Re: Bug in TreeView control
- From: Jan Hyde (VB MVP)
- Re: Bug in TreeView control
- From: MikeD
- Re: Bug in TreeView control
- Prev by Date: Re: Textbox
- Next by Date: Re: Bug in TreeView control
- Previous by thread: Re: Bug in TreeView control
- Next by thread: Re: Bug in TreeView control
- Index(es):
Relevant Pages
|