AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Treeview with databse

Ein Thema von mijack · begonnen am 15. Jul 2007 · letzter Beitrag vom 15. Jul 2007
Antwort Antwort
mijack

Registriert seit: 18. Mai 2007
11 Beiträge
 
Delphi 2007 Enterprise
 
#1

Treeview with databse

  Alt 15. Jul 2007, 10:36
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
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: Treeview with databse

  Alt 15. Jul 2007, 19:24
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:
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;
This code is not tested, but should show some basic principles. Think twice about the TreeView, though.

Regards
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz