因不常用这个控件,现在用其扫描数据库的一个表产生节点,遇到了一些问题,请各位赐教.  1.如何得知一个根节点的深度
      说明:可以有若干个根节点的,每个根节点又有可能有若干子节点和叶子,我想知道点中一个根节点后,如何得到该根节点的深度(即它的层数)  2.我可以得到选中节点的text,请问我如何知道它的index值,

解决方案 »

  1.   

    1、Selected.Level
    2、Selected.Index  在对应父节点中的索引
    Selected.AbsoluteIndex  在整个树中的索引————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————
      

  2.   

    1、在SQL中写一个存储过程来实现,
      这是我回答别人问题写的一存储过程,目的是显示某一节点下的所有子节点,其中本身就有个层次参数,改一下就OK:
    创建测试表加入测试数据:
    create table table1(id char(3),parentid char(3),name char(10))
    insert into table1 values('1','0','化工原料')
    insert into table1 values('2','1','氨类')
    insert into table1 values('3','1','脂类')
    insert into table1 values('4','2','乙氨酸')存储过程如下:
    create procedure showtree
    @id char(3),--要展开的节点
    @no int --层次,传入为1,以后递增。这是存储过程的关键,就是逐层查找子节点
    as
    begin
    if @no=1
       select @no as cno,table1.* into #temp from table1 where parentid=@id
         --如果@no为1,则表示搜索第一层数据,并建立临时表,加入结果数据
    declare @tid char(3)
    declare temp_sear cursor for select id from #temp where cno=@no 
    open temp_sear
    fetch next from temp_sear into @tid
    while @@FETCH_STATUS=0
    begin
      set @no=@no+1 --将层次加1
      insert into #temp select @no as cno,table1.* from table1 where parentid=@tid
      fetch next from temp_sear into @tid
    end 
    close temp_sear
    DEALLOCATE temp_sear
    if @no<32  --最深为32层
       if (select count(*) from #temp where cno=@no)>0 
       exec showtree '',@NO  --此处进行递归
    end
    --select id,parentid,name from #temp order by id
    select max(cno) from #temp 
    go
    测试如下:
    exec showtree '1',1
    2
    exec showtree '2',11
      

  3.   

    对于问题一,亦可将参数@no 改为output参数,然后取输出的@no即可