This is a migrated thread and some comments may be shown as answers.

NodeCheckedChanged with AutoCheckChildNodes

5 Answers 154 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Jean-Philippe Pagé
Top achievements
Rank 1
Jean-Philippe Pagé asked on 25 Nov 2009, 07:07 PM
I was wondering if there is a way to disable the NodeCheckedChanged event from being fired for all children nodes when AutoCheckChildNodes is set to true.

The reason why I want to know this is that I store an xml string inside the tag of each node.  Every node is a possible record in a database.  The xml being stored inside each node contains the information for the current node along with all its children nodes.  When the user checks or unchecks a node, I need to give this xml to another component which in turns inserts or removes the proper information to/from the database.  I know I could keep raising this event for every node and simply keep the info for the current node in the tag, but this could make for a lot of back and forth between components and the database while this way only one call is being made.

I was thinking of keeping a flag inside the NodeCheckedChanged event and checking this flag before processing like the following:
        private void radTreeView1_NodeCheckedChanged(object sender, RadTreeViewEventArgs e)  
        {  
            if (!m_processing)  
            {  
                m_processing = true;  
                // do work....  
                m_processing = false;  
            }  
        }  
 
but I noticed that the calls weren't nested and that it was actually doing all the code before moving on to the next child/sibling node.

Is there a workaround or another event I could use for this?  I want to do the work only once and for the node that was actually checked/unchecked.

5 Answers, 1 is accepted

Sort by
0
Jean-Philippe Pagé
Top achievements
Rank 1
answered on 26 Nov 2009, 06:42 PM
I have found a workaround for this but I am not sure how reliable it is.  I have a member RadTreeNode that I keep and I set its value whenever I enter the NodeMouseDown event.  Then in the NodeCheckedChanged event before doing anything I make sure that the received node is the same node as in the NodeMouseDown event.
private void radTreeView1_NodeCheckedChanged(object sender, RadTreeViewEventArgs e)  
        {  
            if (e.Node == m_ClickedNode)  
            {  
                // Do work here...  
            }  
        }  
 
        private void radTreeView1_NodeMouseDown(object sender, RadTreeViewMouseEventArgs e)  
        {  
            m_ClickedNode = e.Node;  
        } 
0
Martin Vasilev
Telerik team
answered on 27 Nov 2009, 02:51 PM
Hello Jean-Philippe Pagé,

I have already answered in the support ticket concerning this topic. I just want to share my notes here as well:

I think that your work-around is very suitable for the described issue. I only suggest that you clear the m_ClickedNode parameter to avoid any undesired effects from NodeCheckedChanged event:

void radTreeView1_NodeMouseDown(object sender, RadTreeViewMouseEventArgs e)
{
    m_ClickedNode = e.Node;
}
 
private void radTreeView1_NodeCheckedChanged(object sender, RadTreeViewEventArgs e)
{
    if (e.Node == m_ClickedNode)
    {
        Debug.WriteLine("ChangedNode: " + e.Node.Text);
        m_ClickedNode = null;
    }
}

Do not hesitate to contact me again if you have any other questions.

Kind regards,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jean-Philippe Pagé
Top achievements
Rank 1
answered on 30 Nov 2009, 03:27 PM
Thank you Martin, I will add your suggestion into my code.
0
Jean-Philippe Pagé
Top achievements
Rank 1
answered on 21 Dec 2009, 07:20 PM
After doing some more testing we noticed that we had forgotten about a little something with this workaround.... some people are more keyboard punchers than mouse clickers.  This means that I also have to keep track of the m_ClickedNode (which has now been renamed to m_SelectedNode) in the SelectedNodeChanged method.  Good think multiselection is not allowed in my tree.
0
Boyko Markov
Telerik team
answered on 24 Dec 2009, 08:42 AM
Hi Jean-Philippe Pagé,

You can also try the following as a solution:

1. Subscribe to the KeyDown event of RadTreeView
2.  Save the m_SelectedNode in the event handler if the "Space" key is pressed.

void radTreeView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
            {
                m_SelectedNode = this.radTreeView1.SelectedNode;
            }
        }

If you need more information, please do not hesitate to contact us.
I hope this helps.


Greetings,
Boyko Markov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Treeview
Asked by
Jean-Philippe Pagé
Top achievements
Rank 1
Answers by
Jean-Philippe Pagé
Top achievements
Rank 1
Martin Vasilev
Telerik team
Boyko Markov
Telerik team
Share this question
or