Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-07

Adding data field to a child node in a treeview

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Susie Nicol

Hi - me again

I have a Lazarus treeview, which I am populating from several sql queries.

I add child nodes in this way, setting them to one of the fields returned from the query

           while Not SQLQuery1.EOF do
          Begin
          treeview1.items.addchild(treeview1.selected,
SQLQuery1.fields[0].AsString);
           SQLQuery1.Next
          end;

That works of course.

I want to modify the newly added node by setting its data property to another field in the loop - something like

    treeview1.SOMETHING.data := Pointer(SQLQuery1.fields[1].AsInteger);

but the problem is that I can't work out how to identify the newly-added child node. Is it possible?

Thanks in advance
Susie
------
Susie K Nicol
Christchurch
New Zealand.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150704/4509afe9/attachment.html>

Reply by email

Michael Van Canneyt
to Susie Nicol
Susie Nicol wrote 21 lines
Hi - me again I have a Lazarus treeview, which I am populating from several sql queries. I add? child nodes in this way, setting them to one of the fields returned from the query ??? ?????? while Not SQLQuery1.EOF do ????????? Begin ? ????????? treeview1.items.addchild(treeview1.selected, SQLQuery1.fields[0].AsString); ? ?????????? SQLQuery1.Next ????????? end;???? That works of course. I want to modify the newly added node by setting its data property to another field in the loop - something like ??? treeview1.SOMETHING.data := Pointer(SQLQuery1.fields[1].AsInteger); but the problem is that I can't work out how to identify the newly-added child node.? Is it possible?

Not like this. You need to keep a reference when doing an AddChild:

Var
   N : TTreeNode;
begin
   N:=Treeview1.items.addchild(treeview1.selected, SQLQuery1.fields[0].AsString);
   N.data := Pointer(SQLQuery1.fields[1].AsInteger);
end;

Michael.

Reply by email

Howard Page-Clark
to Susie Nicol: Hi - me again I have a Lazarus treeview, which I am populating from several sql queries.…
Susie Nicol wrote 25 lines
Hi - me again I have a Lazarus treeview, which I am populating from several sql queries. I add child nodes in this way, setting them to one of the fields returned from the query while Not SQLQuery1.EOF do Begin treeview1.items.addchild(treeview1.selected, SQLQuery1.fields[0].AsString); SQLQuery1.Next end; That works of course. I want to modify the newly added node by setting its data property to another field in the loop - something like treeview1.SOMETHING.data := Pointer(SQLQuery1.fields[1].AsInteger); but the problem is that I can't work out how to identify the newly-added child node. Is it possible?
var
   node: TTreeNode;
begin
node:=TreeView1.Items.AddChild(TreeView1.Selected,SQLQuery1.Fileds[0].AsString);
node.Data:=pointer(SQLQuery1.Fields[0].AsInteger);
SQLQuery1.Next;
end;

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

Tony Whyman
to Susie Nicol: Hi - me again I have a Lazarus treeview, which I am populating from several sql queries.…

Susie,

You may find the code for TIBTreeView in the IBX for Lazarus package as a useful example of how to create a data aware treeview. Even you don't want to use IBX, the overall approach should work with other DB packages.

Tony Whyman
MWA

Susie Nicol wrote 39 lines
Hi - me again I have a Lazarus treeview, which I am populating from several sql queries. I add child nodes in this way, setting them to one of the fields returned from the query while Not SQLQuery1.EOF do Begin treeview1.items.addchild(treeview1.selected, SQLQuery1.fields[0].AsString); SQLQuery1.Next end; That works of course. I want to modify the newly added node by setting its data property to another field in the loop - something like treeview1.SOMETHING.data := Pointer(SQLQuery1.fields[1].AsInteger); but the problem is that I can't work out how to identify the newly-added child node. Is it possible? Thanks in advance Susie ------ Susie K Nicol Christchurch New Zealand. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150704/75561cbd/attachment-0001.html>

Reply by email

Susie Nicol
to Howard Page-Clark: var node: TTreeNode; begin node:=TreeView1.Items.AddChild(TreeView1.Selected,SQLQuery1.Fil…

Thanks heaps guys. That's great.

Howard Page-Clark wrote 50 lines
On 04/07/2015 09:46, Susie Nicol wrote: > Hi - me again > > I have a Lazarus treeview, which I am populating from several sql queries. > > I add child nodes in this way, setting them to one of the fields > returned from the query > > while Not SQLQuery1.EOF do > Begin > > treeview1.items.addchild(treeview1.selected, > SQLQuery1.fields[0].AsString); > > SQLQuery1.Next > end; > > That works of course. > > I want to modify the newly added node by setting its data property to > another field in the loop - something like > > treeview1.SOMETHING.data := Pointer(SQLQuery1.fields[1].AsInteger); > > but the problem is that I can't work out how to identify the newly-added > child node. Is it possible? > var node: TTreeNode; begin node:=TreeView1.Items.AddChild(TreeView1.Selected,SQLQuery1.Fileds[0].AsString); node.Data:=pointer(SQLQuery1.Fields[0].AsInteger); SQLQuery1.Next; end; --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150704/dccf505a/attachment.html>

Reply by email