Home > Net >  TVirtualStringTree is displaying incorrect data i.e displaying "node" in each cell. How to
TVirtualStringTree is displaying incorrect data i.e displaying "node" in each cell. How to

Time:09-22

I followed the conventional practice of displaying data on TVirtualStringTree. But it displays only the string "node" in each cell. Can someone tell what I am missing here ? Thanks in advance.

My Code:

type
  TRecFileDirectory = record
    FileDirectory: WideString;
    FileDirectoryLock: wordbool;
  end;

  TPRecFileDirectory = ^TRecFileDirectory;

implementation

procedure TForm2.btn4Click(Sender: TObject);
var
  I: Integer;
  NewNode: PVirtualNode;
  ptrFileDir: TPRecFileDirectory;
begin
  vsTree1.BeginUpdate;
  for I := 0 to Length(arrFileDirectory)-1 do
  begin
    NewNode := vsTree1.AddChild(nil);
    ptrFileDir := vsTree1.GetNodeData(NewNode);
    ptrFileDir^.FileDirectory := arrFileDirectory[I].FileDirectory;
    ptrFileDir^.FileDirectoryLock := arrFileDirectory[I].FileDirectoryLock;
  end;
  vsTree1.EndUpdate;
  btn4.caption := btn4.caption ' DONE';
end;

The VirtualStringTree shows data like this

CodePudding user response:

You need to implement an event handler for the OnGetText event, that extracts the string to be displayed from your data, dependant on the column and node that is supplied. For example:

procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
  MyData: TPRecFileDirectory;
begin
  MyData := Node.GetData();
  if Column = 0 then
    CellText := MyData.FileDirectory; 
end;

CodePudding user response:

Set DefaultText property to empty string, e.g. in code or in Inspector

  • Related