如何找到树控件的级别 [英] how to find level of a tree control

查看:75
本文介绍了如何找到树控件的级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp.net c#中查找树结构级别的编号
是否有任何功能或代码可以找到树节点的级别或深度?

i want to find out the numbers of level of a tree structure in asp.net c#
is there any function or any code to find the tree node level or depth

推荐答案

参考:

如果我对您的理解是正确的,那么您想查看一个节点与它的基本节点之间的距离.为此,必须为具有父级的每个节点存储对父级节点的引用.如果没有引用父节点,则该节点位于树的基础上,并且级别为0或1,但是您要为该应用程序计数.

在这种情况下,基本思想是从要查找其级别的节点开始,然后跟随该节点到其父节点的链接.该新节点可以有一个父节点,也可以有一个父节点,依此类推.重复此搜索,直到到达没有父母的节点.您在此搜索中遍历的节点数代表初始节点的深度.

伪代码:
If I understand you correctly, you want to see how far removed a node is from its base node. To do this, you must store a reference to a parent node for each node that has a parent. If there is no parent node referenced, then the node is at the base of the tree and has a level of 0 or 1, however you want to count for this application.

The basic idea in this case would be to start with the node you want to find the level of and follow that node''s link to its parent node. That new node may have a parent, who may have a parent, and so on. Repeat this search until you get to a node with no parents. The number of nodes you traversed in this search represents the initial node''s depth.

Pseudo-code:
node = (the node you want to find the depth of)
count = 1
while node.parent is not null
    count = count + 1
    node = node.parent


这篇关于如何找到树控件的级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆