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

How to cancel a selection event?

3 Answers 217 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Pawz
Top achievements
Rank 1
Pawz asked on 10 Mar 2008, 01:31 AM
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?

3 Answers, 1 is accepted

Sort by
0
Pawz
Top achievements
Rank 1
answered on 10 Mar 2008, 01:32 AM
And I just checked - the standard treeview implements before & after select, with a TreeViewCancelEventArgs parameter which carries the node, action, and a cancel value.
0
Nikolay
Telerik team
answered on 12 Mar 2008, 01:56 PM
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
0
Stefan
Telerik team
answered on 21 Mar 2011, 10:15 AM
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
Tags
Treeview
Asked by
Pawz
Top achievements
Rank 1
Answers by
Pawz
Top achievements
Rank 1
Nikolay
Telerik team
Stefan
Telerik team
Share this question
or