问题描述
我有一个包含数据的数据库表,需要将字段加载到TTreeView
对象中.
I have a database table with data and need to load the fields into a TTreeView
object.
该行:
ItemTree.Items.AddChild(nil, CurrentField_Text);
简单地在顶层添加一个节点.
simply adds a node to the top level.
如何指定要插入的点?
请注意,在遍历表中的数据时,我可以(例如)插入3个顶级项,然后第4个元素实际上是节点2的子元素.
Please note that while looping through the data from the table, I may (for example) insert 3 top level items and then the 4th element is actually the child of node 2.
我该如何指定?
推荐答案
这是直接从我的程序中提取的一些代码,该程序将查询中获取的值插入到树形视图中.
This is some code lifted directly from a program of mine which inserts values taken from a query into a treeview.
tv.items.clear;
with qCustTree do // this is the query which 'feeds' the treeview
try
close;
params[0].asinteger:= qCustWithCallsID.asinteger;
open;
tv.items.BeginUpdate;
while not eof do
begin
father:= fieldbyname ('father').asinteger;
if father = 0
then node:= nil
else node:= FindANode (father);
lastnode:= tv.Items.AddChildObject (node, fieldbyname ('curdate').asstring,
pointer (fieldbyname ('id').asinteger));
next
end;
finally
tv.items.endupdate;
tv.fullexpand;
tv.Selected:= tv.Items[0];
tvchange (nil, tv.Selected);
end;
如果返回的元组的父亲"字段为0,则在树上打开一个新的父节点,否则打开一个新的子节点.
If the 'father' field of the returned tuple is 0, then a new parent node is opened on the tree, otherwise a new child node is opened.
这篇关于如何将层次结构数据从数据库加载到树形视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!