通过定义节点的Key值进行识别,如 treeview1.nodes.add ,,"root"+str(i),ParentNode treeview1.nodes.add "root"+str(i),tvwChild,"child"+str(j),ChildNode 要找父节点,还是要遍历节点 if treeview1.nodes(n).key like "root*" then ...... end if 要找子节点,还是要遍历节点 if treeview1.nodes(n).key like "child*" then ...... end if
n=0
szTmp=Node.FullPath
index=instr(sztmp,"\")
do while index>0
sztmp=mid(sztmp,index+1)
index=Instr(szTmp,"\")
n=n+1
loop
父的if treeview1.selectitem.parent is not nothing then 子的
如下:
type
TMyNode = class(TTreeNode)
private
FFloorNum: integer;
public
property FloorNum: integer read FFloorNum write FFloorNum;
end;
在窗体的最后在CreateNodeClasss事件中加入:
NodeClass := TMyNodeClass;然后你在创建每个节点的时候就可以使用FFloorNum属性了。
NodeClass := TMyNode;
treeview1.nodes.add ,,"root"+str(i),ParentNode
treeview1.nodes.add "root"+str(i),tvwChild,"child"+str(j),ChildNode
要找父节点,还是要遍历节点
if treeview1.nodes(n).key like "root*" then
......
end if
要找子节点,还是要遍历节点
if treeview1.nodes(n).key like "child*" then
......
end if