So rather than doing foreach for row / cell you may want to get exact data for cell by using e. Column Index to extract cell data object from your data source.
cell, an exception occurs and I get a run-time error.
The C# code snippet will enable the data cell validation in a textbox column for entering only none empty strings, which will disable the data validation and display the error indicator at the row header.
Before we validate data to grid cell, we need to cancel the Validate Cell event to prevent the users from exiting the cell until entering a valid editor value or cancelling the edit process.
Meanwhile, we can use the Validate Row event in the same way to prevent the user from exiting the current row.
I have a parent form with one Data Grid View and a button.
When the button is clicked, it opens a child window and when closed, goes back to the parent form.