这个好办,通过递归调用,把节点放到一个list里不就得了
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private List
private void FetchNode(TreeNode node)
{
nodeList.Add(node);
for (int i = 0; i < node.Nodes.Count; i++)
{
FetchNode(node.Nodes[i]);
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.treeView1.Nodes.Count; i++)
{
FetchNode(this.treeView1.Nodes[i]);//递归根节点的所有子节点
}
MessageBox.Show(nodeList.Count + "");
}
}
}