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

[Solved] RadGridView Row Validation

5 Answers 458 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bryan Johnson
Top achievements
Rank 1
Bryan Johnson asked on 27 Aug 2010, 01:55 PM
I using the radgridview row validation.  The validation is working (the row turns red if invalid), but the error messages are not being displayed on hover.   Another problem I'm having is while the row is highlighted in red, the Cancel Edit/Insert button does not cancel the Edit/Insert.  I have to press Esc twice to cancel.

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

Sort by
0
Maya
Telerik team
answered on 27 Aug 2010, 03:01 PM
Hi Bryan Johnson,

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.


Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bryan Johnson
Top achievements
Rank 1
answered on 27 Aug 2010, 03:23 PM
Thanks for the response.  Removing the line you suggested does work, however my error message "Item is required." displays twice inside the hover pop-up.  The Esc key behavior makes sense, but my actual question was why the Cancel Edit/Insert button did not cancel the Edit?  I'm using the telerick command for the buttons and binding them to the grid.  Thanks for your help!   -Bryan

0
Maya
Telerik team
answered on 27 Aug 2010, 05:46 PM
Hello Bryan Johnson,

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.

Best wishes,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bryan Johnson
Top achievements
Rank 1
answered on 27 Aug 2010, 06:06 PM
Thank you again.  The e.ValidationResults must have retained a previously set error message.  I solved the problem by using e.ValidationResults.clear() to clean it out first.  Now the message is not doubled.  Regarding the cancel button, I can live with the default behaviour.  I'll just instruct users to use the Esc key.  Regards, Bryan
0
Maya
Telerik team
answered on 30 Aug 2010, 12:04 PM
Hello Bryan Johnson,

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.

Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Bryan Johnson
Top achievements
Rank 1
Answers by
Maya
Telerik team
Bryan Johnson
Top achievements
Rank 1
Share this question
or