How to hide expand/collapse button in Virtual Treeview?
Asked Answered
O

2

5

I use VirtualStringTree (VST) to display data that is grouped, header-details. I need to have an option to allow user to expand, collapse headers to see details and in some cases I need to show data as static view, where they can't expand, collapse, only see full expanded tree:

Here is example when user can expand, collapse node with child node:

enter image description here

And here is example when I want to prevent user to expand/collapse node and always see all expanded (or whatever is shown):

enter image description here

in this test I control by 'Allow Expand/Collapse/ checkbox.

I prevent expand, collapse by adding:

Allowed:=CheckBox1.Checked;

into OnCollapsing/OnExpanding:

procedure TMainForm.VSTCollapsing(Sender: TBaseVirtualTree;
  Node: PVirtualNode; var Allowed: Boolean);
begin
  Allowed:=CheckBox1.Checked;
end;

procedure TMainForm.VSTExpanding(Sender: TBaseVirtualTree;
  Node: PVirtualNode; var Allowed: Boolean);
begin
  Allowed:=CheckBox1.Checked;
end;

I also show/hide TreeLines base on checkbox with

procedure TMainForm.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
    VST.TreeOptions.PaintOptions:=VST.TreeOptions.PaintOptions + [toShowTreeLines]
  else
    VST.TreeOptions.PaintOptions:=VST.TreeOptions.PaintOptions - [toShowTreeLines];
end;

How can I hide this little plus sign when I want to prevent user to expand, collapse node. Any suggestions?


EDIT:

To clear up the confusion with form icon, this is demo project from Virtual Treeivew 5 demo library. The form in IDE has Delphi XE7 icon, when running the project this old icon appear. Don't know why. Just wanted to make sure it is clear that I use XE7 and not any older Delphi versions, where the same solution might not apply.

In IDE the icon if as XE7 icon:

enter image description here

Oversize answered 10/3, 2016 at 16:42 Comment(4)
On a side-note, your question is tagged Delphi-xe7 yet the icon on your application appears as a very old version of Delphi...?Misericord
Didn't notice that at first...it's a demo project from Virtual Treeview 5 demo library, Minimal demo. IDE shows XE7 icon on Form, when running this old one creeps in.. don't know why.Oversize
Must be the old original .res file holding onto it.Misericord
I added an image of form icon in IDE, so there will be no confusion that I'm asking about XE7 or older Delphi version - in case the same solution is not for older versions.Oversize
D
6

The additional option you're looking for is toShowButtons. Use it in the same place you use toShowTreeLines.

The option is documented in VirtualTrees.pas in the declaration for TVTPaintOption:

    toShowButtons,             // Display collapse/expand buttons left to a node.
Dyspeptic answered 10/3, 2016 at 16:57 Comment(0)
S
1

In addition to @Rob Kennedy's answer, besides the option "toShowButtons", the other option that might be needed (for the top hierarchical level) is the option "toShowRoot"

Sharla answered 19/4, 2023 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.