当用鼠标点某个节点的时候判断他是第几层的节点

解决方案 »

  1.   

    能具体给点代码么,我没怎么用过treeview
      

  2.   

    统计节点属性 .FullPath中"\"的个数,若个个为0则表示是根节点.
    n=0
    szTmp=Node.FullPath
    index=instr(sztmp,"\")
    do while index>0
      sztmp=mid(sztmp,index+1)
      index=Instr(szTmp,"\")
      n=n+1
    loop
      

  3.   

    if treeview1.seleitem.parent is nothing then
      父的if treeview1.selectitem.parent is not nothing then  子的
      

  4.   

    最好的办法是使用自定义节点,比如对于你的问题,可以在节点中添加一个变量表明这是第几层。
    如下:
    type
      TMyNode = class(TTreeNode)
      private
        FFloorNum: integer;
      public
        property FloorNum: integer read FFloorNum write FFloorNum;
    end;
    在窗体的最后在CreateNodeClasss事件中加入:
       NodeClass := TMyNodeClass;然后你在创建每个节点的时候就可以使用FFloorNum属性了。
      

  5.   

    错了,应该是:
    NodeClass := TMyNode;
      

  6.   

    通过定义节点的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