How to cancel a selection event?

4 posts, 0 answers
  1. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 09 Mar 2008 Link to this post

    I've been working on building a treeview that's basically the navigation control for the application, and I've run into a bit of a question.

    When I'm using the events BeforeSelect & AfterSelect, I'm getting the warning that I'm supposed to be using the 'Selected' event. However, the Selected event doesn't have any information attached to it - it implements the standard (object sender, EventArgs e) format, with no information on which node has been selected.

    So, that's one issue - what's the best way to get the information I need now? (Which node has been selected?)

    2nd issue is this: If the user is on node A and has done some editing for that node, and wants to move to node B, I want to warn them about moving away before saving.. So, I want to capture the 'trying to move away' event and cancel the move. How do I do this?
  2. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 09 Mar 2008 Link to this post

    And I just checked - the standard treeview implements before & after select, with a TreeViewCancelEventArgs parameter which carries the node, action, and a cancel value.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 12 Mar 2008 Link to this post

    Hello Pawz,

    Thank you for writing.

    The AfterSelect and BeforeSelect events correspond to the Selected and Selecting events respectively. Selecting has RadTreeViewCancelEventArgs which contains the Node and also has a Cancel property by which you can cancel the selection.

    As to your second question, you can cancel ending the edit mode within the handler of the ValueValidating event. Its CancelEventArgs contain the Cancel property, which you can use to cancel ending the edit mode. However, the Selecting event is fired after the ValueValidating event, so you cannot distinguish whether you finish editing because of an Enter keystroke or because of 'trying to move away' action. You can still implement your own message box in the ValueValidating event handler, which will work in in both cases of trying to close the editor:

    void radTreeView1_ValueValidating(object sender, CancelEventArgs e)  
    {  
        string message = "Do you want to close the editor and to save your results?";  
        string caption = "Save dialog";  
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;  
        DialogResult result;  
     
        result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);  
     
        if (result == DialogResult.No)  
        {  
            e.Cancel = true;  
        }  

    I hope this helps. If you have additional questions, do not hesitate to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 21 Mar 2011 Link to this post

    Hello Pawz,

    Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.
     
    Greetings,
    Stefan
    the Telerik team
Back to Top