rt,不好意思,我是菜菜鸟,请大家指教,请讲详细点

解决方案 »

  1.   

    不会吧? 假设你的TREEVIEW是tr1. 你可是输入tr1.AfterSelect += ...
      

  2.   

    我找不到呀,只有selectedIndexChanged,load,databinding事件呀,就是找不到afterselect事件,很怪呀,还有也没有在CSDN上看到的selectednode属性,有selectednodeIndex事件
      

  3.   

    winform or webform?你编写的是什么类型的程序。
      

  4.   

    to webform呀afterselect是没有的,你如果想做的话,
    方法一:设置treeview的autopostback为true,然后在selectedindexchanged事件中去处理;
    不过这样会产生闪动太厉害。方法二:不用设置treeview的autopostback,但是需要借助js来做,大致如下:
    首先需要增加hidden的input,用来存取当前点击节点的index值,如下取名“NodeIndex”
    //in your page aspx file
    <script language="javascript">
    function setNodeIndex()
    {
    if( yourTree.clickedNodeIndex != "" && yourTree.clickedNodeIndex != "null" )
    document.all("NodeIndex").value=yourTree.clickedNodeIndex;
    else
    document.all("NodeIndex").value=yourTree.selectedNodeIndex;
    }
    </script>// in your page cs file
    // in page load event
    if( !IsPostBack )
         yourTree.Attributes.Add( "onclick", "setNodeIndex();" );
    else
    {
    if( NodeIndex.Value != "" && NodeIndex.Value.ToLower() != "null" )
    {
    TreeNode tnCurrent = yourTree.GetNodeFromIndex( 
    yourTree.SelectedNodeIndex );
            // do what you want with "tnCurrent"
    }
    }
      

  5.   

    Sorry!
    change
    if( NodeIndex.Value != "" && NodeIndex.Value.ToLower() != "null" )
    {
    TreeNode tnCurrent = yourTree.GetNodeFromIndex(
    yourTree.SelectedNodeIndex );
    // do what you want with "tnCurrent"
    }
    with
    if( NodeIndex.Value != "" && NodeIndex.Value.ToLower() != "null" )
    {
    yourTree.SelectedNodeIndex = NodeIndex.Value;
    TreeNode tnCurrent = yourTree.GetNodeFromIndex(
    yourTree.SelectedNodeIndex );
    // do what you want with "tnCurrent"
    }
      

  6.   

    谢谢愚翁大哥了,那我想得到现在选中的结点的text,为什么我用textBox1.text=tnCurrent.text不行呀,
      

  7.   

    通过tnCurrent.Text应该没有什么问题,
    不过,你在使用之前,先看看tnCurrent是否有效,单步调试看看。
      

  8.   

    TO 愚翁大哥:
    可是可以了,但是要有别的控件发生一次postback事件textbox里的值才刷新一次,不能做到viewTree上点击一下textboxt里的值就变一下吗?
      

  9.   

    如果你不想提交,可以在js中直接去修改,例如:
    function setNodeIndex()
    {
    if( yourTree.clickedNodeIndex != "" && yourTree.clickedNodeIndex != "null" )
    {
    var Node = yourTree.getTreeNode( yourTree.clickedNodeIndex ) ;
    document.All( "yourTextboxName" ).Value = Node.Value;
    }
    }
      

  10.   

    我的treeview控件没有clickedNodeIndex事件呀
      

  11.   

    to 我的treeview控件没有clickedNodeIndex事件呀这是js代码
    //in your page aspx file
    <script language="javascript">
    function setNodeIndex()
    {
    if( yourTree.clickedNodeIndex != "" && yourTree.clickedNodeIndex != "null" )
    {
    var Node = yourTree.getTreeNode( yourTree.clickedNodeIndex ) ;
    document.All( "yourTextboxName" ).Value = Node.Value;
    }
    }
    </script>// in your page cs file
    // in page load event
    if( !IsPostBack )
    yourTree.Attributes.Add( "onclick", "setNodeIndex();" );
      

  12.   

    你要用哪个textbox来显示,修改上面js部分yourTextboxName即可
      

  13.   


    我把加在html里的代码粘出来吧,请愚翁大哥再看一下
    <script language="javascript">
    function setNodeIndex()
    {
    if( this.TreeView1.ClickedNodeIndex != "" && this.TreeView1.ClickedNodeIndex != "null" )
    var Node = this.TreeView1.getTreeNode( this.TreeView1.ClickedNodeIndex ) ;
                           document.All( "TextBox1" ).Text= Node.Text;
      
      }
    </script>
    但是还是报不支持此属性和方法,我也试了把ClickedNodeIndex 换成selectedNodeIndex试了也是一样,请帮忙 了
      

  14.   

    不要使用this,这个在js中不认
    have a try!<script language="javascript">
    function setNodeIndex()
    {
    if( TreeView1.ClickedNodeIndex != "" && TreeView1.ClickedNodeIndex != "null" )
    var Node = TreeView1.getTreeNode( TreeView1.ClickedNodeIndex ) ;
    document.All( "TextBox1" ).Text= Node.Text;}
    </script>