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?