计算树视图中的所有节点 [英] Count all nodes in a treeview
本文介绍了计算树视图中的所有节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码仅计算树视图中的父节点或根节点,
如何计算树视图中的所有节点?
//一个方式
int NodeCounter = 0;
foreach(TreeView1.Nodes中的TreeNode currentNode)
NodeCounter ++;
//其他方式
int total = TreeView1.Nodes.Count;
解决方案
怎么样...
public int GetTotalNodes(TreeView treeView)
{
返回this.GetTotalNodes(treeView .Nodes);
}
private int GetTotalNodes(TreeNodeCollection节点)
{
int rootNodes = nodes.Count;
foreach(节点中的TreeNode节点)
{
rootNodes + = this.GetTotalNodes(node .Nodes);
}
返回rootNodes;
}
问候,
" John Rogers" < jo ************ @aol.comescribióenel mensaje de
noticias:eW ************** @ TK2MSFTNGP02 .phx.gbl ...
此代码仅计算树视图中的父节点或根节点,
如何计算所有树视图中的节点?
//单向
int NodeCounter = 0;
foreach(TreeView1.Nodes中的TreeNode currentNode) )
NodeCounter ++;
//其他方式
int total = TreeView1.Nodes.Count;
* * * * * * * * private int GetTotalNodes(TreeNodeCollection节点)
* * * * * * * * {
* * * * * * * * * * * * int rootNodes = nodes.Count;
* * * * * * * * * * * * foreach(节点中的TreeNode节点)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * rootNodes + = this.GetTotalNodes(node.Nodes);
* * * * * * * * * * * *}
* * * * * * * * * * * *返回rootNodes;
* * * * * * * *}
所以,计算所有节点不仅仅是树节点...我不明白...... *因为
总是*
// CY
谢谢,这很有效。
Pedro Luna Montalvo < pe ******* @ hotmail.com写信息
新闻:3C *********************** *********** @ microsof t.com ...
怎么样...
This code only counts the parent nodes or rootnodes in a treeview,
how do you count all the nodes in a treeview?
// one way
int NodeCounter = 0;
foreach (TreeNode currentNode in TreeView1.Nodes)
NodeCounter++;
// other way
int total = TreeView1.Nodes.Count;
解决方案
What about...
public int GetTotalNodes(TreeView treeView)
{
return this.GetTotalNodes(treeView.Nodes);
}
private int GetTotalNodes(TreeNodeCollection nodes)
{
int rootNodes = nodes.Count;
foreach (TreeNode node in nodes)
{
rootNodes += this.GetTotalNodes(node.Nodes);
}
return rootNodes ;
}
Greetings,
"John Rogers" <jo************@aol.comescribió en el mensaje de
noticias:eW**************@TK2MSFTNGP02.phx.gbl...This code only counts the parent nodes or rootnodes in a treeview,
how do you count all the nodes in a treeview?
// one way
int NodeCounter = 0;
foreach (TreeNode currentNode in TreeView1.Nodes)
NodeCounter++;
// other way
int total = TreeView1.Nodes.Count;
* * * * * * * * private int GetTotalNodes(TreeNodeCollection nodes)
* * * * * * * * {
* * * * * * * * * * * * int rootNodes = nodes.Count;
* * * * * * * * * * * * foreach (TreeNode node in nodes)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * rootNodes += this.GetTotalNodes(node.Nodes);
* * * * * * * * * * * * }
* * * * * * * * * * * * return rootNodes ;
* * * * * * * * }
so, count all nodes not just tree nodes... I dont get it... *as
always*
//CY
Thanks, that worked great.
"Pedro Luna Montalvo" <pe*******@hotmail.comwrote in message
news:3C**********************************@microsof t.com...What about...
这篇关于计算树视图中的所有节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文