##########为什么我的treeview控件没有afterselect事件呀???? rt,不好意思,我是菜菜鸟,请大家指教,请讲详细点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不会吧? 假设你的TREEVIEW是tr1. 你可是输入tr1.AfterSelect += ... 我找不到呀,只有selectedIndexChanged,load,databinding事件呀,就是找不到afterselect事件,很怪呀,还有也没有在CSDN上看到的selectednode属性,有selectednodeIndex事件 winform or webform?你编写的是什么类型的程序。 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 eventif( !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"}} Sorry!changeif( NodeIndex.Value != "" && NodeIndex.Value.ToLower() != "null" ){TreeNode tnCurrent = yourTree.GetNodeFromIndex(yourTree.SelectedNodeIndex );// do what you want with "tnCurrent"}withif( NodeIndex.Value != "" && NodeIndex.Value.ToLower() != "null" ){yourTree.SelectedNodeIndex = NodeIndex.Value;TreeNode tnCurrent = yourTree.GetNodeFromIndex(yourTree.SelectedNodeIndex );// do what you want with "tnCurrent"} 谢谢愚翁大哥了,那我想得到现在选中的结点的text,为什么我用textBox1.text=tnCurrent.text不行呀, 通过tnCurrent.Text应该没有什么问题,不过,你在使用之前,先看看tnCurrent是否有效,单步调试看看。 TO 愚翁大哥:可是可以了,但是要有别的控件发生一次postback事件textbox里的值才刷新一次,不能做到viewTree上点击一下textboxt里的值就变一下吗? 如果你不想提交,可以在js中直接去修改,例如:function setNodeIndex(){ if( yourTree.clickedNodeIndex != "" && yourTree.clickedNodeIndex != "null" ) { var Node = yourTree.getTreeNode( yourTree.clickedNodeIndex ) ; document.All( "yourTextboxName" ).Value = Node.Value; }} 我的treeview控件没有clickedNodeIndex事件呀 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 eventif( !IsPostBack )yourTree.Attributes.Add( "onclick", "setNodeIndex();" ); 你要用哪个textbox来显示,修改上面js部分yourTextboxName即可 我把加在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试了也是一样,请帮忙 了 不要使用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> 什么是句柄?什么又是指针! 请问这个Paint事件怎么没有执行 晕,vs2005打包的安生装包是病毒? DataGridView表格中填数据插入数据库的问题…… WPF imageButton 怎么实现trigger,单击改变button里的image 多线程如何访问界面上的某一个控件,并返回控件的值! 怎么样记录用户对程序的所有的操作日志? 如何发送邮件并添加附件 timer控件的属性,如何在窗口设计器中设置? 高手来看看这个问题: 如何用c#在操作系统中建立一个新的帐户 #####求C++树定义转换为c#定义#####
方法一:设置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"
}
}
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"
}
不过,你在使用之前,先看看tnCurrent是否有效,单步调试看看。
可是可以了,但是要有别的控件发生一次postback事件textbox里的值才刷新一次,不能做到viewTree上点击一下textboxt里的值就变一下吗?
function setNodeIndex()
{
if( yourTree.clickedNodeIndex != "" && yourTree.clickedNodeIndex != "null" )
{
var Node = yourTree.getTreeNode( yourTree.clickedNodeIndex ) ;
document.All( "yourTextboxName" ).Value = Node.Value;
}
}
//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();" );
我把加在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试了也是一样,请帮忙 了
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>