VirtualStringTree - embed controls in cells - control is not displayed

So, my final game here should be able to list items (e.g. TListView in vsReport) using the add / remove buttons inside the client area.

Example:

|----------------| |Old Item 1 X | |Old Item 2 X | |Add new item... | | | |----------------| 

If you know about a component that does this without any extra work, please let me know!

So, I selected the red “X” and use TJvTransparentButton (Jedi Components - JVCL) to display it. It controls the press / not pressed states and displays only the image. I used TButton original, but I don’t need all the fluff that goes around the glyph.

Now I save the image button in the record associated with each node.

The code is as follows:

 procedure TfrmMain.AddNewAccount(const Username, Password: String); var Data : PTreeData; XNode : PVirtualNode; Begin XNode := vstAccounts.AddChild(nil); If vstAccounts.AbsoluteIndex(XNode) > -1 Then begin Data := vstAccounts.GetNodeData(Xnode); Data^.Column0 := Username; Data^.Column1 := ''; Data^.DeleteButton := TJvTransparentButton.Create(nil); With Data^.DeleteButton Do begin Parent := vstAccounts; Left := 0; Top := 0; Width := 16; Height := 16; Anchors := []; AutoGray := False; BorderWidth := 0; FrameStyle := fsNone; Images.ActiveImage := iListView; Images.ActiveIndex := 0; end; end; end; 

In the OnAfterCellPaint event, I control the positioning of the image button as follows:

 procedure TfrmMain.vstAccountsAfterCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellRect: TRect); var Data : PTreeData; begin If Column = 1 Then begin Data := vstAccounts.GetNodeData(Node); If Assigned(Data) Then begin With Data^.DeleteButton Do begin BoundsRect := CellRect; end; end; end; end; 

Now the problem is that this does not display the element at all. I know that the image from TImageList is beautiful, because I can create a button at design time, and it looks great at runtime.

I also know that this code should work, because if I make TJvTransparentButton a regular TButton (without changing the logic of the code), it works fine and displays well!

The only thing I can think of is that TButton inherits from TWinControl and TJvTransparentButton inherits from TControl.

Any ideas?

+6
source share
2 answers

I assume that TJvTransparentButton is a TGraphicControl and as such is displayed as part of the parent background (that Tlabel will always be behind TEdit or TButton in the same Parent).
TButton is a TWinControl and, as such, is drawn on top of the parent and above or below other WinControls in the same parent.

So, either you draw TJvTransparentButton again after the usual draw of the cell (updating BoundsRect is not enough), or you use WinControl.
For example, using TPanel with TJvTransparentButton in it should work.

Disclaimer: I am not familiar with VirtualStringTree and TJvTransparentButton ...

+3
source

You are doing it wrong. You must write your own editor for TVirtualStringTree that implements the IVTEditLink interface. Then, in the OnCreateEditor event, you need to create your editor:

 procedure TForm1.VSTCreateEditor(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink); begin EditLink:=TStringEditLink.Create; end; 

You can get more information here .

+3
source

Source: https://habr.com/ru/post/904564/


All Articles