Here is my validation code:
private void ListItemsGrid_RowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e) { RegListItems currentRow = e.Row.DataContext as RegListItems; if (currentRow.key_value == "" || currentRow.key_value == null) { GridViewCellValidationResult validationResult = new GridViewCellValidationResult(); validationResult.PropertyName = "key_value"; validationResult.ErrorMessage = "Item is required."; e.ValidationResults.Add(validationResult); e.IsValid = false; } }
5 Answers, 1 is accepted
The fact that the ErrorMessage does not show on hovering the cell is a known issue. However, it has been fixed in our latest internal build and you can download it later today. For the time being, if you want the Message to appear with the version you are using, you need to remove the last line:
e.IsValid = false;As for the necessity of pressing the Exc button twice, this is the expected behavior as the first click cancels the cell editing and the second one - the insertion/editing.
Maya
the Telerik team
I have tried to reproduce the issue with the double appearance of the ErrorMessage but unfortunately I was not able to. I am sending you the sample project on which I have tested the problem.
As for cancelling the Edit when using RadGridViewCommands, the internal logic behind them does not handle the case when the data inside the row fails the RowValidation. If you share more details about the purpose of using commands for cancelling it instead of using the Esc button, we may be able to provide you with an appropriate solution.
Maya
the Telerik team
In case your application requires the usage of a button and it is far more appropriate for you than clicking on the "Esc" key, you may implement the following workaround:
1. Define a RadButton like:
<telerik:RadButton Content="Cancel" Command="telerik:RadGridViewCommands.CancelRowEdit" CommandTarget="{Binding ElementName=clubsGrid}" />2. Set the Property of RadGridView ActionOnLostFocus:
<telerik:RadGridView Name="clubsGrid"
RowValidating="clubsGrid_RowValidating" ActionOnLostFocus="None" ItemsSource="{Binding Clubs}" AutoGenerateColumns="False" >The second steps is necessary as the default behavior of the grid on LostFocus is to commit edit.
Maya
the Telerik team