NodeCheckedChanged with AutoCheckChildNodes

6 posts, 0 answers
  1. Jean-Philippe Pagé
    Jean-Philippe Pagé avatar
    7 posts
    Member since:
    Aug 2009

    Posted 25 Nov 2009 Link to this post

    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.
  2. Jean-Philippe Pagé
    Jean-Philippe Pagé avatar
    7 posts
    Member since:
    Aug 2009

    Posted 26 Nov 2009 Link to this post

    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;  
            } 
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 27 Nov 2009 Link to this post

    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.
  5. Jean-Philippe Pagé
    Jean-Philippe Pagé avatar
    7 posts
    Member since:
    Aug 2009

    Posted 30 Nov 2009 Link to this post

    Thank you Martin, I will add your suggestion into my code.
  6. Jean-Philippe Pagé
    Jean-Philippe Pagé avatar
    7 posts
    Member since:
    Aug 2009

    Posted 21 Dec 2009 Link to this post

    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.
  7. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 24 Dec 2009 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready