![]() |
Treeview with databse
Hi all
i have a Table and i want to populate a treeview from this Table . Let me suppose the following : In my table i have : Name:String ; First_Name :String; Age : Integer; Adr :String; City :String; Steet :String ; so i want to load this from my Table into the TreeView like this : Contact ( as the Parent ) |_Name |_First_Name |_Age |_Adr |_City ( Child of Adr ) |_Street ( Child of Adr ) how can i do this . thanks |
Re: Treeview with databse
Hi,
since you end up mixing names and values in one single node.text you should not be very happy with a TreeView. Just to show a technical solution I will provide some code:
Delphi-Quellcode:
This code is not tested, but should show some basic principles. Think twice about the TreeView, though.
type
TDemoForm = class(TForm) TreeView: TTreeView; Table: TTable; Button: TButton; procedure ButtonClick(Sender: TObject); private procedure AddInfo(ds: TDataSet; node: TTreeNode; names: array of string); end; var DemoForm: TDemoForm; implementation {$R *.dfm} procedure TDemoForm.AddInfo(ds: TDataSet; node: TTreeNode; names: array of string); var i: Integer; begin with ds, node do for i := Low(names) to High(names) do node.Owner.AddChild(node, FieldByName(names[i]).AsString); end; procedure TDemoForm.ButtonClick(Sender: TObject); var bm: TBookmark; begin TreeView.Items.Clear; with Table do begin bm := GetBookmark; DisableControls; First; while not Eof do begin AddInfo(Table, TreeView.Items.AddChildObject(nil, 'Contact', Pointer(RecNo)), ['NAME', 'FIRST_NAME'] ); Next; end; GotoBookmark(bm); FreeBookmark(bm); EnableControls; end; end; Regards |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:44 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz