Re: Bug in TreeView control

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Korey Mateer" <KoreyMateer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1AC59247-A776-44DD-ACAF-42286BF95831@xxxxxxxxxxxxxxxx

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

So, iow, you want yours to look just like it does in Explorer?

Using Spy++ that comes with Dev Studio, I looked at the styles that are
applied to the treeview in Explorer:

TVS_HASBUTTONS
TVS_EDITLABELS
TVS_SHOWSELALWAYS
TVS_TRACKSELECT
TVS_SINGLEEXPAND
TVS_NONEVENHEIGHT

Not sure this will help, the window class of the treeview in explorer is
SysTreeView32, while the window class of the one in the control is
TreeView20WndClass, but probably worth a try.


-Mark




Thanks again for your time and consideration.

-Korey Mateer



.



Relevant Pages

  • Re: Bug in TreeView control
    ... Uses lines to link items at the root of the tree-view control. ... I have found no inconsistencies in the Visual Basic or Platform SDK ... To get the plus\minus box on the root level, ...
    (microsoft.public.vb.controls)
  • Re: How should control images should be handled?
    ... > as icons and other decorations in the form of images. ... > part of the control. ... you configure the HttpHandler to process all requests for *.MyControl, ... > root is actually the domain root, while in the development system the root ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: Adventures in DRM land: Sony
    ... SOmeone has to control that ... ...and be there when I want to install &frammis. ... Taking away root is a control-phreak issue. ... corp far more in lost productivity than the materials savings. ...
    (comp.sys.ibm.pc.hardware.chips)
  • How should control images should be handled?
    ... Some times user controls and custom web controls need images such ... part of the control. ... I typically put all my images in the img directory at the root of my web ... But then on my development machine my ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • RE: Can I use more than one style in a treeview control at the root no
    ... As for the ASP.NET 2.0 TreeView control, the TreeNode style is arranged ... Can I use more than one style in a treeview control at the root ... | child 1.1 ...
    (microsoft.public.dotnet.framework.aspnet)