We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

No validation unless user selects another row.

I have a situation in my production code where I need to "manually" invoke the row validation. In my case I'm not using the SfDataGrid add new row functionality, instead the user pressing a button to add a row.

Closing the view invokes the save (back to database) functionality, but I don't want to save any records if the validation fails. If the user adds a row and edits it and closes the view the validation is not invoked.

You can achieve the same result by running the following Syncfusion sample

wire the RowValidating event for pasted content in datagrid | WPF - SfDataGrid (syncfusion.com)

Method:

Start the application

Edit the employee name and change it to Null.

Close the application and the private void DataGrid_RowValidating(object sender, RowValidatingEventArgs e) method does not get called. It is only called when you select another row in the table.

How do I invoke the validation, if the focus changes from a row in the grid to any control outside of the grid






3 Replies 1 reply marked as answer

SJ Sathiyathanam Jeyakumar Syncfusion Team December 6, 2022 06:54 PM UTC

Hi Zeljko,

The row validating event occurs when the edited cells try to commit the row data or lose focus. But as per your scenario, you want to trigger the row validating event when the window gets closed while the cell is in editing. However, we are still analyzing your requirement to "trigger the row-validating event when the window is closing" and will update you with further details on December 9, 2022.


Regards

Sathiyathanam






VS Vijayarasan Sivanandham Syncfusion Team December 9, 2022 07:48 PM UTC

Zeljko,

We are still analyzing your requirement to "trigger the row-validating event when the window is closing" and will update you with further details on December 13, 2022.



SJ Sathiyathanam Jeyakumar Syncfusion Team December 13, 2022 04:27 PM UTC

Zeljko,

You can trigger the row validating event when the window is closing by calling the method CheckValidationAndEndEdit() in Window.Closing event, and here you can handle the window closing CheckValidationAndEndEdit() method's returned value. Refer to the below screenshots and a sample to get more information.




Attachment: Synchronizegrid_fc7385f5.zip

Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon