procedure TForm1.FormShow(Sender: TObject);
var
old_dept: string;
i: integer;
Node,NewNode:TELTreeItem;
begin
VirtualTable1.Filtered:=True;
VirtualTable1.Active:=True;
Node:=nil; // 避免編譯時出現警告訊息
ElTree1.Selected:=Nil;
ElTree1.Items.Clear();
ElTree1.Items.BeginUpdate();
try
old_dept := #13#10;
VirtualTable1.First;
for i:=0 to VirtualTable1.RecordCount-1 do
begin
if VirtualTable1.FieldByName('bank').AsString <> old_dept then
begin
Node:=ElTree1.Items.Add(Nil,VirtualTable1.FieldByName('bank').AsString);
Node.ShowCheckBox:= True ;
//Node.CheckBoxType := ectCheckBox ;
//Node.CheckBoxEnabled := True ;
Node.UseStyles := True ;
Node.MainStyle.OwnerProps := False;
Node.MainStyle.FontSize:=10;
Node.MainStyle.FontName:=Screen.MenuFont.Name;
//Node.ImageIndex:=13;
old_dept:=VirtualTable1.FieldByName('bank').AsString;
end;
NewNode:=ElTree1.Items.AddChild(Node,VirtualTable1.FieldByName('accout').AsString);
NewNode.ColumnText.Add(VirtualTable1.FieldByName('money').AsString);
//NewNode.ShowCheckBox:= True ;
//NewNode.CheckBoxType := ectCheckBox ;
//NewNode.CheckBoxEnabled := True ;
NewNode.UseStyles := True ;
NewNode.MainStyle.OwnerProps := False;
NewNode.MainStyle.FontSize:=10;
NewNode.MainStyle.FontName:=Screen.MenuFont.Name;
//NewNode.ImageIndex:=12;
VirtualTable1.Next;
end;
finally
ElTree1.Items.EndUpdate();
end;
end;
procedure TfrmMain.TreeItemFocused(Sender: TObject);
begin
//顯示所按的標籤文字
//Caption:=ElTree1.ItemFocused.text;
//顯示他爸爸的標籤文字
if ElTree1.itemFocused.Parent <> nil then
Caption:=ElTree1.ItemFocused.Parent.text;
//顯示第一個結點的標籤文字
//Caption := ElTree1.Items.GetFirstNode.Text;
//顯示所有結點的數目
//Caption := inttostr(ElTree1.Items.Count);
end;
(2)說明
ElTree1.Items.GetFirstNode 返回TREEVIEW的第一個節點,函數類型為
:TTreeNode
ElTree1.Items.Count 返回當前TreeView的全部節點數,整數
ElTree1.Selected.Level 返回當前選中節點的在目錄樹中的級別,
根目錄為0
ElTree1.Selected.Parent 返回當前選中節點上級節點,函數類型為
:TTreeNode
參考網址
http://www.delphibbs.com/keylife/iblog_show.asp?xid=19823
1 則留言:
Intercombase - quality translation complex text any of more than 140 languages. IT Translation, Chemical Translation, Industrial Translation - Summit affordable.
French Translation - [url=http://www.intercombase.com]Greek[/url]
張貼留言