unit Unit2;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, VirtualTrees,
Vcl.StdCtrls;
type
TMyDataSet =
record
Name:
String;
Desc:
String;
end;
PMyDataSet = ^TMyDataSet;
type
TForm2 =
class(TForm)
vstTable: TVirtualStringTree;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure vstTableGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText:
string);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
Node: PVirtualNode;
Data: PMyDataSet;
begin
ShowMessage(IntToStr(vstTable.GetMaxColumnWidth(0, False)));
//62px
ShowMessage(IntToStr(vstTable.GetMaxColumnWidth(1, False)));
//77px
vstTable.BeginUpdate;
Node := vstTable.FocusedNode;
if Assigned(Node)
then
begin
Data := vstTable.GetNodeData(Node);
if Assigned(Data)
then
begin
Data^.
Name := Data^.
Name + '
xyz 12345';
Data^.Desc := Data^.Desc + '
xyz 12345';
end;
end;
vstTable.EndUpdate;
//Workaround or musst have?
//vstTable.InvalidateNode(Node);
ShowMessage(IntToStr(vstTable.GetMaxColumnWidth(0, False)));
//62px and 106px with the "workaround"
ShowMessage(IntToStr(vstTable.GetMaxColumnWidth(1, False)));
//127px
vstTable.Header.AutoFitColumns(False, smaAllColumns);
end;
procedure TForm2.FormCreate(Sender: TObject);
var
Node: PVirtualNode;
Data: PMyDataSet;
Index: Integer;
begin
vstTable.NodeDataSize := SizeOf(TMyDataSet);
vstTable.BeginUpdate;
for Index := 1
to 10
do
begin
Node := vstTable.AddChild(
nil);
Data := vstTable.GetNodeData(Node);
if Assigned(Data)
then
begin
Data^.
Name := IntToStr(
Index)+'
. Bla bla';
Data^.Desc := '
Bla bla bla bla';
end;
end;
vstTable.EndUpdate;
vstTable.Header.AutoFitColumns(False, smaAllColumns);
end;
procedure TForm2.vstTableGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType;
var CellText:
string);
var
Data: PMyDataSet;
begin
Data := vstTable.GetNodeData(Node);
if Assigned(Data)
then
begin
case Column
of
0: CellText := Data^.
Name;
1: CellText := Data^.Desc;
end;
end;
end;
end.