-->

Delphi VirtualStringTree Drawing

2019-08-10 12:17发布

问题:

I have been trying to figure these 2 things out:

1) How do I change the whole row's color in code? Like, when the VT looks like a ListView?

2) How do I make the Checkboxes indent aswell? My child checkboxes and on the same "indent?" as my root checkboxes.

Thanks!

回答1:

1)

procedure VSTBeforeItemErase(
  Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
  ItemRect: TRect; var ItemColor: TColor;
  var EraseAction: TItemEraseAction);
begin
  EraseAction := eaColor;
  ItemColor := clLime;
end;

2) The indent setting for each node check box separately is IMHO impossible. The tree has its Indent property, which sets the indention for all nodes (including their check boxes). Internally the AdjustCoordinatesByIndent and PaintCheckImage methods are called, but both are hidden for you. Modification of one of them can help you, but you need to be very specific, I would say the best would be to create your own component descendant.

If you want to create something what is in property page of the advanced example, you need to add nodes to more than one level in the tree hierarchy.

For your inspiration ...

var CurrentNode: PVirtualNode;
    CurrentSubnode: PVirtualNode;

begin
  VirtualStringTree1.Indent := 50; // this increases indention for all nodes in the tree

  CurrentNode := VirtualStringTree1.AddChild(nil); // create a node to the root
  CurrentNode.CheckType := ctCheckBox; // check support of a node
  CurrentSubnode := VirtualStringTree1.AddChild(CurrentNode); // create a subnode to your first node
  CurrentSubnode.CheckType := ctCheckBox; // check support of a node
end;


回答2:

1) Try adding toFullRowSelect to TreeOptions.SelectionOptions.

2) I can't answer that. Maybe try toFixedIndent.