0

I am working with TVirtualStringTree, and I would like to display a 'delete' icon when the user hovers over a specific node or the node is selected.

Example in VSCode Explorer View:

VSCode Explorer view

Is GetImageIndex the correct method to achieve this?

How can I handle the click event?

1
  • 2
    It would probably be better if you enable Hot tracking and then use combination of HotNode Property , OnHotChange Event to track the node under the mouse cursor and StateImages Property to control which images of certain tree node are displayed. I'm not sure about detecting click on specific part of tree node in order to detect click on delete image Commented May 8 at 7:01

1 Answer 1

0

I tried the OnHotChange Event, but I couldn't figure out what to do with it. My solution uses GetImageIndex:

procedure TForm1.VstGetImageIndex(Sender : TBaseVirtualTree; Node : PVirtualNode; Kind : TVTImageKind; Column : TColumnIndex; var Ghosted : Boolean; var ImageIndex : TImageIndex);
begin
    case Kind of
        ikNormal, ikSelected :
        case Column of
            COL_NUM: begin 
                if (Vst.HotNode = Node) then begin
                    ImageIndex := DEL_IMAGE_IDX; // Vst.Images should be set
                end else begin
                    ImageIndex := -1;
                end;
            end;
        end;
    end;
end;

OnClick is also easy:

procedure TForm1.VstNodeClick(Sender : TBaseVirtualTree; const HitInfo : THitInfo);
begin
    if hiOnNormalIcon in HitInfo.HitPositions then begin
        Vst.DeleteNode(HitInfo.HitNode);
        Exit;
    end;
// every other click handling ...
end;
Sign up to request clarification or add additional context in comments.

Comments

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.