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.

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

Comments

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.
  ...
);

2 Comments

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.
I would prefer using Expanded property as like @ain pointed out, node States is supposed to be an implementation detail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.