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
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?
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
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
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