We help IT Professionals succeed at work.

TVirtualStringTree problem

gfdas
gfdas asked
on
TVirtualStringTree problem

To change text

I don't know how to change text (caption) of existing node in TVirtualStringTree. In help section I found some code and I tried to run it, but I didn't succeed. Where is a problem ? Please help. Thanks.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  VirtualTrees;

type
  TForm1 = class(TForm)
    VirtualStringTree1: TVirtualStringTree;
    procedure VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
      ParentNode, Node: PVirtualNode;
      var InitialStates: TVirtualNodeInitStates);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

type
TTreeData = record
  Text: WideString;
  URL: String[255];
  CRC: LongInt;
  isOpened: boolean;
  ImageIndex: Integer;
end;
PTreeData = ^TTreeData;

procedure TForm1.VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
  ParentNode, Node: PVirtualNode;
  var InitialStates: TVirtualNodeInitStates);

var
  NodeData: PTreeData;
begin
  NodeData := VirtualStringTree1.GetNodeData(Node);
  NodeData.Text := 'a test';
  NodeData.ImageIndex := 1;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
VirtualStringTree1.RootNodeCount:=10;
end;

end.
Comment
Watch Question

BRONZE EXPERT
Top Expert 2004
Commented:
hi again,

there is an event onGetText, where you can provide the text like

procedure TF_AG.TreeView1GetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: Integer; TextType: TVSTTextType;
  var Text: WideString);
Var AData : PItemInfo;
begin
  AData := Sender.GetNodeData(Node);
  Text := AData.Name;
end;

meikl ;-)

Author

Commented:
Thenks.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.