Cancelling Selection async/await

I have just started using the SfTreeView and was excited to see that there is a SelectionChanging event. The problem that I am running into is I want to mark the event as Async (even though the return type is void this is allowed because of the EventHandler) I need to make an async call depending on the result of that call I may or may not cancel the selection change. Attached is a program to recreate the issue.

Thanks,

Justin

Attachment: TreeViewTesting_LookatMe_f40b0036.zip

4 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team August 28, 2020 01:51 PM UTC

Hi Justin, 

Thanks for contacting Syncfusion support.  

We are little unclear with your requirement. We are unable to understand the need for you to make the SelectionChanging event handling method as async and canceling the event for some cases. Kindly provide more details about your requirement and the need to make the event async and what behavior you need to achieve in the provided sample. It will be more helpful for us to understand your exact requirement and to provide a prompt solution at earlier.  

Regards, 
Mohanram A. 



JM Justin Mason August 28, 2020 03:37 PM UTC


I have a TreeView that when selected drives the view, by selecting one item a specific view is displayed and by selecting another item a different view is displayed. When the selection is made the user is able to make changes to the data and the model then needs to be saved at a later point in time (when the tree selection changes to another item). The code I am using to display a message and to save the data are both awaitable functions and require the use of the async keyword, to rewrite either of these functions to a non-async method is not an option. I was hoping that I could use the SelectionChanging event because of the ability to cancel the selection if the user decided they really did not want to change to another selection.

I have changed the test program to simulate the issue, the top tree view is handling the SelectionChanging event asynchronously. When the user click on a tree view item a message box is displayed the selection is made before the message box is dismissed and the cancel is not recognized. The bottom tree view handles the SelectionChanging event synchronously and works as expected.

Thanks,

Justin

Attachment: TreeViewTesting_New_79dab325.zip


MA Mohanram Anbukkarasu Syncfusion Team August 31, 2020 02:28 PM UTC

Hi Justin, 

Thanks for the update.  

We have checked the provided sample and we are able to understand the scenario. We are currently working on this and we will update with further details on or before 2nd September 2020. We appreciate your patience until then.  

Regards, 
Mohanram A. 



MA Mohanram Anbukkarasu Syncfusion Team September 2, 2020 02:02 PM UTC

Hi Justin, 

Thanks for your patience. 

We have analyzed the reported scenario in our end. The SelectionChanging event will be triggered while selecting an item. If it is marked as async and awaiting for a method to complete its execution, meanwhile the selection will be processed and the item will be selected. This is happening while marking SeletionChanging event handler method as async. This will not work as per  your requirement. You have to use those methods as sync methods. 

Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon