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

async / await inside row validating event

1 Answer 193 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 01 Dec 2016, 03:57 PM

I use the gridview's row validating event to perform some validations. 

All database methods in my persistence framework are defined async. The validation method needs database access, so it's also defined as async and returns a Task<bool>. 

The row validating event handler awaits this validation method. If the validation fails, the isValid property is set to false.

Everything works fine as long as there is no asynchronous database call and the code execution runs synchronously. As soon as I have real asynchronism, the grid view doesn't wait for the completion of the validating event handler anymore. It continues its internal validation and the RowEditEnded event raises - although the RowValidating event handler hasn't finished already. 

How can I force the grid view to wait for the asynchronous validation? I know that there are some issues with events and the async/await pattern and I tried different declaration types - without success.

Thanks for you help!

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 06 Dec 2016, 03:19 PM
Hello,

The current implementation of RadGridView's validation logic executes the raising of the Validating event synchronously, so modification of this logic won't be possible unless internal changes are made. However,as INotifyDataErrorInfo supports async validation, a possible option is to pass the editing operation to complete and if errors occur, RadGridView would be notified by the ErrorsChanged event.

Regards,
Ivan Ivanov
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or