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

Invalid Cell Validation updates VM

4 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 06 May 2016, 08:04 AM

I have a grid that has a cell validating event, which sets the isValid property of the edit to false when required. As expected, I am unable to move away from the cell until I correct the error. However, I notice that the grid is still updating the underlying VM with the incorrect value. Surely this is wrong.

This is causing me an issue, because the user can still initiate a save (due to a complicated winform/wpf integration), and as such persist the incorrect value.

4 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 1
answered on 06 May 2016, 08:23 AM

OK, so I think this might be because I have a cell edit template defined as follows

<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<TextBox Text="{Binding TableName}" Margin="0,-2" Validation.ErrorTemplate="{StaticResource ErrorToolTipTemplate}"/>
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>

Should the textbox be bound to the VM as well?

 

0
Stefan
Telerik team
answered on 11 May 2016, 07:31 AM
Hello Jason,

I am investigating the cause for this behavior, however I need more time for this. I will update you as soon as I have a result.

Thank you in advance for your patience.

Best Regards,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Jason
Top achievements
Rank 1
answered on 11 May 2016, 08:07 AM

As I suggested above, the textbox is also bound to the VM, so it updates the VM outside of the grid flow of control. This is alluded to in a comment (somewhat buried) that in order for templated cells to follow the validation of grid, you need to create a custom column. So that's what I did, and it solved my issue.

I would suggest the documentation be update on the "Setting CellTemplate and CellEditTemplate" page, to highlight this, as it already does on the document section "Create Custom Editor with RadGridView", where it says

    more important this [CellEditTemplate] bypasses the RadGridView validation and editing engine

Had I seen these on the page about templating, I could've saved myself a few hours of hair pulling

0
Stefan
Telerik team
answered on 13 May 2016, 11:51 AM
Hello Jason,

Thank you for your valuable feedback.

Indeed, the CellEditTemplate bypasses the built-in validation mechanism of the control and the solution is to implement a custom column. I am glad that you have already found it. We will update our documentation as soon as possible. I have also added Telerik points to your account as a gratitude for your suggestion.

All the best,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Jason
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or