Home > Back-end >  Delphi treeview create node tree structure
Delphi treeview create node tree structure

Time:09-26

The default parent for 1001
Child nodes dynamically created for 1001001100002, etc, in turn, to increase the...
Warrior to do; Thank you

CodePudding user response:

http://docwiki.embarcadero.com/CodeExamples/XE8/en/TreeViewAddChild_%28Delphi%29
 procedure TForm1. Button1Click (Sender: TObject); 
Var
MyTreeNode1 MyTreeNode2: TTreeNode;
The begin
With TreeView1. Items do
The begin
The Clear; {Remove any existing nodes.}
MyTreeNode1:=Add (nil, 'RootTreeNode1'); {the Add a root node.}
{the Add a child node to the node just added.}
AddChild (MyTreeNode1, 'ChildNode1');

{the Add another root node}
MyTreeNode2:=Add (MyTreeNode1, 'RootTreeNode2');
{difference MyTreeNode2 to a child.}
AddChild (MyTreeNode2, 'ChildNode2');

{Change MyTreeNode2 to ChildNode2}
{the Add a child node to it.}
MyTreeNode2:=TreeView1 Items [3].
AddChild (MyTreeNode2, 'ChildNode2a');

{the Add another child to ChildNode2, after ChildNode2a.}
AddChild (MyTreeNode2, 'ChildNode2b');

{the Add another root node.}
Add (MyTreeNode1, 'RootTreeNode3');
end;
end;

CodePudding user response:

reference 1st floor ksrsoft response:

http://docwiki.embarcadero.com/CodeExamples/XE8/en/TreeViewAddChild_%28Delphi%29
 procedure TForm1. Button1Click (Sender: TObject); 
Var
MyTreeNode1 MyTreeNode2: TTreeNode;
The begin
With TreeView1. Items do
The begin
The Clear; {Remove any existing nodes.}
MyTreeNode1:=Add (nil, 'RootTreeNode1'); {the Add a root node.}
{the Add a child node to the node just added.}
AddChild (MyTreeNode1, 'ChildNode1');

{the Add another root node}
MyTreeNode2:=Add (MyTreeNode1, 'RootTreeNode2');
{difference MyTreeNode2 to a child.}
AddChild (MyTreeNode2, 'ChildNode2');

{Change MyTreeNode2 to ChildNode2}
{the Add a child node to it.}
MyTreeNode2:=TreeView1 Items [3].
AddChild (MyTreeNode2, 'ChildNode2a');


{the Add another child to ChildNode2, after ChildNode2a.}
AddChild (MyTreeNode2, 'ChildNode2b');

{the Add another root node.}
Add (MyTreeNode1, 'RootTreeNode3');
end;
end;

Is how to set the node number; Is the child node Numbers automatically add three digits behind 001002, etc

CodePudding user response:

Define a variable, circulation plus 1
 var 
Id: integer;
The begin
Id:=0;
Inc (id);
Caption:=FormatFloat (' 000 ', id);

CodePudding user response:

The
reference 3 floor ksrsoft response:
define a variable, cycle 1
 var 
Id: integer;
The begin
Id:=0;
Inc (id);
Caption:=FormatFloat (' 000 ', id);

There's no way that if 1001001 into the parent node is child node Numbers for 1001001001

CodePudding user response:

 procedure TForm1. Button1Click (Sender: TObject); 
Var
MyTreeNode1: TTreeNode;
I, j: integer;
Si, sj: string;

The begin
With TreeView1. Items do
The begin
The Clear; {Remove any existing nodes.}

{the Add a child node to the node just added.}
For I:=1 to 10 do
The begin
Si:=FormatFloat (' 1000 ', I);
MyTreeNode1:=Add (nil, Si); {the Add a root node.}
For j:=1 to 10 do
The begin
Sj:=Si + FormatFloat (' 000 ', j);
AddChild (MyTreeNode1, sj);
end;
end;

end;

end;

CodePudding user response:

reference 5 floor ksrsoft reply:
 procedure TForm1. Button1Click (Sender: TObject); 
Var
MyTreeNode1: TTreeNode;
I, j: integer;
Si, sj: string;

The begin
With TreeView1. Items do
The begin
The Clear; {Remove any existing nodes.}

{the Add a child node to the node just added.}
For I:=1 to 10 do
The begin
Si:=FormatFloat (' 1000 ', I);
MyTreeNode1:=Add (nil, Si); {the Add a root node.}
For j:=1 to 10 do
The begin
Sj:=Si + FormatFloat (' 000 ', j);
AddChild (MyTreeNode1, sj);
end;
end;

end;

end;

Doesn't he? Assuming that 100101 is the parent node new button how to increase children do statement how to write

CodePudding user response:

 unit Unit1; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ComCtrls;

Type
TForm1=class (TForm)
TreeView1: TTreeView;
For: TButton;
Button2: TButton;
Button3: TButton;
Procedure Button1Click (Sender: TObject);
Procedure Button2Click (Sender: TObject);
Procedure Button3Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure TForm1. Button1Click (Sender: TObject);//add a root node
Var
NowNode: TTreeNode;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related