1

This sounds like a stupid question but I have tried everything I can think of without success. How can I change the Icon image of a VirtualStringTree Node when that node is expanded. i.e. when Node is collapsed I want to show a closed folder icon and when its expanded I want to show an Open folder icon.

In GetImageIndex I cannot see how to tell if the node is expanded or not. Kind only tells me when it is selected.

ain
  • 22,394
  • 3
  • 54
  • 74
John Barrat
  • 810
  • 4
  • 15

2 Answers2

2

The TBaseVirtualTree has Expanded property to check wether the given node is expanded or not:

procedure TForm1.VTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
          Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
begin
  if Sender.Expanded[Node] then begin
     ...
  end;
end;
ain
  • 22,394
  • 3
  • 54
  • 74
1

The Node: PVirtualNode; parameter of the OnGetImageIndex() event can tell you through it States property whether it is expanded or not.

procedure TForm1.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: TImageIndex);
begin
  if vsExpanded in Node.States then
    // select image as needed
  ...
end;

Background:

From the source (unit VirtualTrees)

TVirtualNodeState = (
  ...
  vsExpanded,          // Set if the node is expanded.
  ...
);
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • 2
    I would consider node's properties as an implementation detail, for most (all?) things there is a method which is meant to retrieve given information. – ain Aug 25 '18 at 11:48
  • 1
    I would prefer using `Expanded` property as like @ain pointed out, node `States` is supposed to be an implementation detail. – Victoria Aug 25 '18 at 15:03