Asp.net 树视图 - 单击同一节点时不会触发事件

发布于 2024-11-01 08:15:03 字数 158 浏览 0 评论 0原文

有没有办法在选择节点两次时引发 SelectedNodeChanged 事件。我无法使用代码“treeview.SelectedNode.Selected = false”,因为我必须显示树的选定节点,但同时,我想要一些事件,以便我可以捕获节点上的点击。有什么办法可以做到吗?

提前致谢

Is there any way to raise the SelectedNodeChanged event on selecting the node twice. I cant use the code "treeview.SelectedNode.Selected = false" as i have to show the selected node of the tree but at the same time, i want some event so that i can capture the click on node. Is there any way to do so ?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮年 2024-11-08 08:15:03

您可以做的是将代码放在另一个事件中,例如预渲染,您可以通过布尔类变量(例如 blnIsChanged)来确定选择是否已更改。该值的默认值 false 仅在 SelectedNodeChanged 事件中设置为 true,因此您可以在预渲染(或在 SelectedNodeChanged 事件之后触发的任何事件)中使用 if 语句,如果 blnIsChanged = false 并执行该操作,则可以执行您的代码如果它 = true 则什么也没有。

例子:

Partial Class YourPageWithaAtreeView  
    Inherits System.Web.UI.Page  
Dim _blnSelectionChanged as Boolean = false



Protected Sub MyTree_SelectedNodeChanged(byval sender as object, byval e as eventargs) handles MyTree.SelectedNodeChanged  
   _blnSelectionChanged = true //The selection changed
End Sub
Protected Sub MyTree_PreRender(byval sender as object, byval e as eventargs) handles MyTree.PreRender
    if _blnSelectionChanged = false Then
      //Because the boolean is not true that means that 
      //the selected node didn't change
      //insert the code you want to execute when the user
      //clicks the already selected node
    end if
End Sub

What you could do is put the code in another event like the prerender and you can determine if the selection has changed by having a boolean class variable, blnIsChanged for example. This value has the default value of false is only set to true in the SelectedNodeChanged event so you can have an if statement in the prerender (or any event that would fire after the SelectedNodeChanged event) that can execute your code if blnIsChanged = false and do nothing if it = true.

Example:

Partial Class YourPageWithaAtreeView  
    Inherits System.Web.UI.Page  
Dim _blnSelectionChanged as Boolean = false



Protected Sub MyTree_SelectedNodeChanged(byval sender as object, byval e as eventargs) handles MyTree.SelectedNodeChanged  
   _blnSelectionChanged = true //The selection changed
End Sub
Protected Sub MyTree_PreRender(byval sender as object, byval e as eventargs) handles MyTree.PreRender
    if _blnSelectionChanged = false Then
      //Because the boolean is not true that means that 
      //the selected node didn't change
      //insert the code you want to execute when the user
      //clicks the already selected node
    end if
End Sub
我最亲爱的 2024-11-08 08:15:03

是的,标准 TreeView 控件没有 OnNodeClick() 事件,这确实很烦人。

我最终使用了 Telerik 的版本(' RadTreeView') 确实支持此事件。

另一种方法是以迂回的方式编写您自己的处理程序,如下所述:
http://www.programmersheaven.com/mb/csharp/ 341363/341363/事件处理-treeview/

Yes, it's really annoying that there's no OnNodeClick() event for the standard TreeView control.

I ended up using Telerik's version (the 'RadTreeView') which does support this event.

The other way is to write your own handler in a round-about way as described here:
http://www.programmersheaven.com/mb/csharp/341363/341363/event-handling-treeview/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文