找出同一级的父结点下有几个子结点?

sbxtzhl 2003-08-24 05:13:07
谢谢
...全文
36 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bxh2dai 2003-08-24
  • 打赏
  • 举报
回复
你的意思是不是如下:
1
2
5
6
3
当我点几5的时候,得到的是1,2,3如果是这样的话,代码如下:
var
thisnode ,tnode: TTreeNode;
str : string;
begin
str :='';
thisnode := TreeView1.Selected.Parent;
tnode := thisnode;
while thisnode <> nil do
begin
str := str+thisnode.Text;
thisnode := thisnode.getNextSibling;//向下找

end;
thisnode := tnode;
while thisnode <> nil do
begin

thisnode := thisnode.getPrevSibling;//向上找
if thisnode<> nil then
str := str+thisnode.Text;
end;
showmessage(str);
end;
sbxtzhl 2003-08-24
  • 打赏
  • 举报
回复

回复人: yxw1314(mosquito) ( ) 信誉:100 2003-08-22 09:05:00 得分:0


var
j,i,k:integer;
str:string;
begin
str:='';
for i:=0 to treeview1.Items.Count do begin
if treeview1.Items.Item[i].Text=treeview1.Selected.Text then begin
k:=i;
break;
end;
end;
for i:=0 to k-1 do
str:=str+ #13#10+treeview1.Items.Item[i].Text ;
showmessage(str);
end;
如果要同层节点,在if 条件处加上treeview1.items.item[i].parent=treeview1.selected.parent,就可以了。
你试验一下吧!


使用上面的方面,虽然能显示,但却显示了当前数据项以上的所有父节点和子节点,
我需要在同层节点下面的数据项上单击后,显示当前数据项的上面的几个父节点。
请教高手
noall 2003-08-24
  • 打赏
  • 举报
回复
直接用count?
qingzhen 2003-08-24
  • 打赏
  • 举报
回复
首先
parent.getfirstchild
然后循环
getnextsibling
就得了

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧