![]() |
TreeView nach VirtualStringTree
Liste der Anhänge anzeigen (Anzahl: 2)
Hallo Leute,
ich zerbrech mir hier gerade übelst den Kopf. Hab im Forum und Tutorials gesucht aber nix gefunden :cry: Die Ausgangsstellung: Habe eine TreeView, die ich mit Daten einer DB fülle. Das geht wunderbar.
Delphi-Quellcode:
Das Problem
//****************************************************************************//
//fill nodes with records from database procedure TFMain.UpdateNodes(Node: TTreeNode; DS: TpFIBDataSet; Field: String); var // DSCount: Integer; IsExp: Boolean; SQL: String; begin //query of used categories DS.Close; SQL := 'select ' + Field + ' from ' + Field +', SONG '; SQL := SQL + 'where SONG.' + Field + '_ID = ' + Field + '.ID '; SQL := SQL + 'group by ' + Field + ' order by ' + Field; DS.SelectSQL.Clear; DS.SelectSQL.Add(SQL); DS.Open; DS.Last; DS.First; //formal thing IsExp := TVMain.Items[Node.Index].Expanded; //delete all children of the node and fill in new TVMain.Items.Item[Node.Index].DeleteChildren; while not DS.Eof do begin TVMain.Items.AddChild(Node, DS[Field]); Application.ProcessMessages; DS.Next; end; TVMain.Items.Item[Node.Index].Expanded := IsExp; Node.Text := Field + 's (' + IntToStr(DS.RecordCount) + ')'; end; //****************************************************************************// //****************************************************************************// Das ganze möchte ich jetzt mit einem VirtualStringTree machen. Ich bin nach dem Tutorial gegangen von Mike Lischke. Es funktioniert nur, wenn ich FocusedNode benutze. Ich möchte aber die Childs einer meiner Hauptnodes erneuern (z.B. Genre) Als erstes meine Datenstruktur:
Delphi-Quellcode:
Die Hauptnodes erzeuge ich so
TBasicNodeData = class
protected cImageIndex: Integer; cName: ShortString; public constructor Create; overload; constructor Create(vName: ShortString; vIIndex: Integer = 0); overload; property Name: ShortString read cName write cName; property ImageIndex: Integer read cImageIndex write cImageIndex; end; rSectionsData = record BasicND: TBasicNodeData; end; var FMain: TFMain; ndLibrary, ndArtist, ndAlbum, ndGenre, ndLanguage, ndPlaylist: PVirtualNode;
Delphi-Quellcode:
Die Childs werden hier erzeugt
procedure TFMain.CreateSectionNode(Node: PVirtualNode;
Caption: String); var NodeD: ^rSectionsData; begin VSTSections.NodeDataSize := SizeOf(rSectionsData); Node := VSTSections.AddChild(nil); NodeD := VSTSections.GetNodeData(Node); NodeD.BasicND := TBasicNodeData.Create(Caption); end; procedure TFMain.FormCreate(Sender: TObject); begin CreateSectionNode(ndLibrary, 'Library'); CreateSectionNode(ndArtist, 'Artists'); CreateSectionNode(ndAlbum, 'Albums'); CreateSectionNode(ndGenre, 'Genres'); CreateSectionNode(ndLanguage, 'Languages'); CreateSectionNode(ndPlaylist, 'Playlist'); end;
Delphi-Quellcode:
Wenn ich statt ndGenre FocusedNode einsetze funktioniert es, aber halt nicht dort wo ich will :wall:
procedure TFMain.Button1Click(Sender: TObject);
var NodeD: ^rSectionsData; Node: PVirtualNode; begin DMMedia.ZQ1.First; while NOT DMMedia.ZQ1.Eof do begin Node := VSTSections.AddChild(ndGenre); NodeD := VSTSections.GetNodeData(Node); NodeD.BasicND := TBasicNodeData.Create(DMMedia.ZQ1Genre.AsString); DMMedia.ZQ1.Next; end; end; |
Re: TreeView nach VirtualStringTree
:cheers: Ich glaub ich sollte öfters mal ein Glas Wein trinken :mrgreen:
Hab doch glatt übersehen dass den PVirtualNodes garnix zugewiesen wird. Hab aus der procedure ne function gemacht und siehe da es geht Also hier mal die function:
Delphi-Quellcode:
So aufzurufen:
function TFMain.CreateSectionNode(Node: PVirtualNode;
Caption: String): PVirtualNode; var NodeD: ^rSectionsData; begin VSTSections.NodeDataSize := SizeOf(rSectionsData); Result := VSTSections.AddChild(Node); NodeD := VSTSections.GetNodeData(Result); NodeD.BasicND := TBasicNodeData.Create(Caption); end;
Delphi-Quellcode:
Und dann funktioniert auch das endlich
procedure TFMain.FormCreate(Sender: TObject);
begin ndLibrary := CreateSectionNode(nil, 'Library'); ndArtist := CreateSectionNode(nil, 'Artists'); ndAlbum := CreateSectionNode(nil, 'Albums'); ndGenre := CreateSectionNode(nil, 'Genres'); ndLanguage := CreateSectionNode(nil, 'Languages'); ndPlaylist := CreateSectionNode(nil, 'Playlist'); end;
Delphi-Quellcode:
procedure TFMain.Button1Click(Sender: TObject);
var NodeD: ^rSectionsData; Node: PVirtualNode; begin DMMedia.ZQ1.First; while NOT DMMedia.ZQ1.Eof do begin Node := VSTSections.AddChild(ndGenre); NodeD := VSTSections.GetNodeData(Node); NodeD.BasicND := TBasicNodeData.Create(DMMedia.ZQ1Genre.AsString); DMMedia.ZQ1.Next; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:53 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