asked on
ASKER
var
Node, Node2:TTreeNode;
begin
Node:=aTreeView.Items.AddChild(nil, 'MAIN1');
Node.ImageIndex:=0; // for example, set an image (using aTreeView.Images)
Node2:=aTreeView.Items.AddChild(Node, 'SUB1');
Node2.ImageIndex:=1; // another image for sub items
Node2:=aTreeView.Items.AddChild(Node, 'SUB2');
Node2.ImageIndex:=1; // another image for sub items
Node:=aTreeView.Items.AddChild(nil, 'MAIN2');
Node.ImageIndex:=0;
Node2:=aTreeView.Items.AddChild(Node, 'SUB1');
Node2.ImageIndex:=1; // another image for sub items
end;
ASKER
procedure TForm1.TreeView1Click(Sender: TObject);
begin
if TreeView1.Selections[0].Level = 0 then
ShowMessage('Main '+ TreeView1.Selections[0].Text)
else
ShowMessage('Sub '+ TreeView1.Selections[0].Text);
end;
procedure TForm1.TreeView1Click(Sender: TObject);
var
i:integer;
begin
if TreeView1.SelectionCount > 0 then
begin
//showmessage('There are '+ IntToStr(TreeView1.SelectionCount) + ' items selected');
for i:= 0 to TreeView1.SelectionCount-1 do
begin
if TreeView1.Selections[i].Level = 0 then
ShowMessage('Main '+ TreeView1.Selections[i].Text)
else
ShowMessage('Sub '+ TreeView1.Selections[i].Text);
end;
end;
end;
ASKER
ASKER
procedure TForm1.TreeView1Click(Sender: TObject);
var
Path: String;
function GetNodePath(ANode: TTreeNode): string;
var
Node: TTreeNode;
begin
Result := ANode.Text;
Node := ANode.Parent;
while Node <> nil do
begin
Result := Node.Text + '->' + Result;
Node := Node.Parent;
end;
end;
begin
if Assigned(TreeView1.Selected) then
Path := GetNodePath(TreeView1.Selected);
ShowMessage(Path);
end;
procedure TForm1.TreeView1Click(Sender: TObject);
var
i:integer;
begin
for i:= 0 to TreeView1.SelectionCount-1 do
begin
if TreeView1.Selections[i].Text = 'Information' then
form1.show
else
if TreeView1.Selections[i].Text = 'test' then
form2.show
else
if TreeView1.Selections[i].Text = 'test2' then
form3.show;
end;
end;
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
Path: String;
function GetNodePath(ANode: TTreeNode): string;
var
Node: TTreeNode;
begin
Result := ANode.Text;
Node := ANode.Parent;
while Node <> nil do
begin
Result := Node.Text + '->' + Result;
Node := Node.Parent;
end;
end;
begin
if Assigned(TreeView1.Selected) then
Path := GetNodePath(TreeView1.Selected);
ShowMessage(Path);
end;
Treeview1.Items.AddObject(nil, 'Information', Form1);
Treeview1.Items.AddObject(nil, 'Test', Form2);
Treeview1.Items.AddObject(nil, 'Test2', Form3);
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
if Assigned(Node.Data) and (TObject(Node.Data) is TForm) then
TForm(Node.Data).Show;
end;
ASKER
ASKER
Node.Textthat's in my project update, but it's to late. lol, i hope another question like this, lol
and also during on change node value, it displays the current node.
The OnChange event seems to be much better for you
Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.
TRUSTED BY