treeview 如何得到它的层次
我想在TREEVIEW里面想得到第几级
我的代码如下,但会出错要怎么写?
private void treeView1_Click(object sender, EventArgs e)
{
if (treeView1.SelectedNode.Level == 2)
MessageBox.Show(treeView1.SelectedNode.Text);
}
------解决方案--------------------treeView1.SelectedNode会为null的情况
//用NodeMouseClick捕获
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Level == 2)
MessageBox.Show(e.Node.Text);
}