public void getScore()

 
    string clsName=null;
    for(int i=0;i<this.className.Nodes.Count;i++)
    {
if(this.className.Nodes[i].IsSelected)
{
   clsName=this.className.Nodes[i].Text;
}
}
className是我定义好的一个父节点,下面有些子节点(父节点和子节点都在添加到了treeView里面)。然后在界面上选中一个子节点,并将它的Text取出来。请问是以上的方法吗?
还有就是,用的事件是
private void treeView1_AfterSelect(object sender,                    System.Windows.Forms.TreeViewEventArgs e)
{}
我后面的程序要用到clsName,但是感觉取出来的值不对呢?请高手朋友帮我看一下。有什么更好的方法,也请指教一下,谢谢!!

解决方案 »

  1.   

    或许可以在clsName=this.className.Nodes[i].Text;后边加个break;试下
      

  2.   

    className是我定义好的一个父节点,下面有些子节点(父节点和子节点都在添加到了treeView里面)。然后在界面上选中一个子节点,并将它的Text取出来。请问是以上的方法吗?
    还有就是,用的事件是
    private void treeView1_AfterSelect(object sender,                    System.Windows.Forms.TreeViewEventArgs e)
    {}
    ================
    其实 就是用这个 事件 
     e.Node.Text  ==就是 你所选择的节点的 值