日期:2014-05-20 浏览次数:21027 次
//所有节点的个数
int count = treeView1.GetNodeCount(true);
//当前节点序号
void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
int sum = getIndex(e.Node, 0);
MessageBox.Show(sum.ToString());
}
int getIndex(TreeNode node, int sum)
{
if (node.PrevNode == null)
{
if (node.Parent == null)
{
return sum + 1;
}
else
{
return getIndex(node.Parent, sum + 1);
}
}
else
{
sum += node.PrevNode.GetNodeCount(true) + 1;
return getIndex(node.PrevNode, sum);
}
}