Home > Back-end >  Delphi treeview in question
Delphi treeview in question

Time:09-28

-- -- --
China
+ jiangsu
Nanjing
-- suzhou
- nantong

+ guangdong
- guangzhou
- east anhui
- taizhou

Add LBL1, LBL2 controls
I've built above the trees in the treeview, excuse me, in a program, I click on the "jiangsu province", how to get LBL1 "jiangsu" value (title), then click the "nanjing", how to get LBL2 "nanjing" this value, while the LBL1 constant

Thank you very much!!

CodePudding user response:

Whether the LBL1, LB2, only inefficient reading a value respectively?

CodePudding user response:

Whether LBL1, LB2, only read a value respectively? To be clear,

CodePudding user response:

In the treeview using selecteditem onselect event. HasChildNode (presumably this name) method to determine whether leaf nodes,
Is a leaf node is updated lbl2, or update lbl1,

CodePudding user response:

Then click on the "nanjing
"SelectedItem="nanjing"
SelectedItem. Parent="jiangsu"

CodePudding user response:

Click on the "jiangsu province", selected. Level=0
Then click on the "nanjing", selected. Level=1

Comprehensive article on this and said, is enough,

CodePudding user response:

 
Void __fastcall TForm1: : TreeView1GetSelectedIndex (TObject * Sender,
TTreeNode * Node)
{
If (TreeView1 - & gt; Selected - & gt; Level==1)
{
Edit1 - & gt; Text=TreeView1 - & gt; Selected - & gt; The Text;
}
Else if (TreeView1 - & gt; Selected - & gt; Level==2)
{
Edit2 - & gt; Text=TreeView1 - & gt; Selected - & gt; The Text;
}
}


CodePudding user response:

//estimated after the original poster is to click on the node, can be displayed on the lbl1 and lbl2 node information, more intuitive interface a bit
Procedure changeLBLCaption (Node: TTreeNode)
The begin
If the node. The parent=nil then
//the first layer, "Chinese", no need to deal with the
exit;
If the node. HasChildNode then
//the second floor, the building Lord to deal with the
The begin
Lbl1. Caption:=Node. The Text;
Lbl2. Caption:=' ';
exit;
End
The else begin
Lbl1. Caption:=Node. The Parent. The Text;
Lbl2. Caption:=Node. The Text;
exit;
end;
end;

CodePudding user response:

 1, set the global variable KK, initial value 1 

2, the TreeView MouseUp events:
Procedure TShowTextFrm. TreeView1MouseUp (Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var NowNode: TTreeNode;
The VCL: TComponent;
The begin
TreeMouthKeyUp;//mouse other operating
NowNode:=TreeView1. Selected;
If NowNode. The HasChildren then//leaf node
The begin
The VCL:=FindComponent (' Label '+ IntTostr (KK));
(VCL As TLabel). Caption:=NowNode. Text;
Kk:=kk + 1;
end;
end;


The above code, which in turn Label (a dozen), in turn, select the value of the TreeView

CodePudding user response:

To establish a Treenode class
Var
Node: TTreenode;
After with you to create the treeview
Use with treeview. Items do
The begin
Node:=add (nil, 'nanjing');
Label1. Text:=selected. The text;
end;

CodePudding user response:

GetNodeAt (X, Y)
  • Related