1

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

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

The problem is not that. Its when i select the same node twice. First time, the event gets fired, but the second time it doesnt fire.
Right because the second time the selection isn't changing so the selectednodechanged event wouldn't fire. My suggestion is a way to keep track of whether the selected node changed yourself and if it didn't in a separate event execute your code. If you would like me to edit my answer with a code example I could.
0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.