Ulugbek Posted July 29, 2013 Posted July 29, 2013 Hi All Who can help me How work or how fill treeview from database.. I need this for items table structure Items CREATE TABLE [goods] ( [id] integer NOT NULL PRIMARY KEY AUTOINCREMENT, [description] varchar(255), [parentid] integer, [isgroup] integer, [code] VARCHAR(25), [note] VARCHAR(2048), All Items TV LCD LED VIDEO Quote
adragan Posted July 29, 2013 Posted July 29, 2013 procedure TMainForm.LoadMenu; var nod1:TUniTreeNode; procedure AddSons(xnod:TUniTreeNode; pid:integer); var q:TUniQuery; // or q:TZQuery, TAdoQuery or the DB engine you work with nod2:TUniTreeNode; begin q:=TUniQuery.Create(Self); try q.Connection:=UniMainModule.Conn; q.Close; q.SQL.Clear; q.SQL.Add('select * from goods'); q.SQL.Add('where parent_id=:pid'); q.SQL.Add('order by id'); q.ParamByName('pid').Value :=pid; q.Open; while not q.eof do begin nod2:=TreeView.Items.AddChild(xNod, q.FieldByName(' whatever field holds the text of the line ').AsString); Nod2.ImageIndex:=0; //Or the id of the picture from the ImageList AddSons(Nod2, q.FieldByName('id').AsInteger); //Next level ! Recursiv !! q.Next; end; q.Close; finally q.Free; end; end; begin with TreeView do begin Items.Clear; Sel.Close; //Sel is a TUniQuery that is allready on the form Sel.SQL.Clear; Sel.SQL.Add('select * from goods where parent_id=0 order by id'); //The linked list starts from parent_id=0 Sel.Open; while not Sel.EOF do begin nod1:=Items.Add(nil, Sel.FieldByName(' field you what you want to display in the line..... ').AsString); Nod1.ImageIndex:=0; AddSons(Nod1, Sel.FieldByName('id').AsInteger); Sel.Next; end; Sel.Close; end; end; N.B. Replace the fields with the name of the ones you want. The list can go indefinitely deep. Check that you do not generate an eternal loop. Have fun !! 1 Quote
Ulugbek Posted July 29, 2013 Author Posted July 29, 2013 how about add group delete edit edit add subgroup in runtime Quote
adragan Posted July 29, 2013 Posted July 29, 2013 You edit, add, delete from the goods table. Ex: id parent_id description ============================== 1 0 TV 2 0 VIDEO 3 1 LCD 4 1 LED 5 2 SAMSUNG 6 2 SONY ..... and so on Quote
Ulugbek Posted July 30, 2013 Author Posted July 30, 2013 I want to add by TreeView but how.. I want new group and I stay in Treeview and add node or childnode after then refresh node or reopen or itemsearch can stay new node some like But How? Quote
adragan Posted July 30, 2013 Posted July 30, 2013 There is a demo for that in the Demo directory of the installation. Quote
Ulugbek Posted July 30, 2013 Author Posted July 30, 2013 can you sample share treeview with data? Quote
Ulugbek Posted August 13, 2013 Author Posted August 13, 2013 Hi ALL Help me how add node or child nod in runtime I want add group or subgroup some like as EhlibTree or DevexpressTree in runtime Quote
Sherzod Posted August 13, 2013 Posted August 13, 2013 Help me how add node or child nod in runtime? Hi Ulugbek. If I understand correctly, then you can: UniTreeView1.Items.AddChild (nil, 'Test node'); UniTreeView1.Items.AddChild (UniTreeView1.Selected, 'Test child node'); To save the data in the database can be something like this: I'm using Firebird ... I can advise the following: At the beginning of the addition of nodes to use in the Data property node ( AUniTreeNode.Data: = TObject (ID); ) ; If you add a child node, you can use the following code: 1. It is necessary to generate the ID in the code, not in the database, you can use FireBird: SELECT GEN_ID (<GeneratorName>, <increment>) FROM DB $ DATABASE; (further be a parent node to the other nodes); 2. You can add in the beginning of the database, and then in UniTree ...... //sample code var ID: Integer; ANode: TUniTreeNode; AChildNode: TUniTreeNode; begin ....... ANode: = UniTreeView1.Selected; AChildNode := UniTreeView1.Items.AddChild (ANode, 'test child node'); AChildNode.Data: = TObject (your generated ID) ; // Insert into DataBase //insert into yourTable (ID, PARENT_ID, DESCRIPTION .....) //values (:ID, :PARENT_ID, :DESCRIPTION .....) //yourDataSet.ParamByName ('ID').asInteger: = your generated ID; //yourDataSet.ParamByName ('PARENT_ID').asInteger: = Integer (ANode.Data); //yourDataSet.ParamByName ('DESCRIPTION').asString := 'test child node'; ........... end; Sincerely Quote
Ulugbek Posted August 13, 2013 Author Posted August 13, 2013 Thank's can you show full example? or sample demo with database thank;s advance 1 Quote
Sistema Fenix Posted October 5, 2013 Posted October 5, 2013 Thank's can you show full example? or sample demo with database thank;s advance +1 Quote
SayeyeZohor Posted October 29, 2019 Posted October 29, 2019 On 8/13/2013 at 8:14 PM, Ulugbek said: Thank's can you show full example? or sample demo with database thank;s advance @Sherzod Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.