Invalid Cell Validation updates VM

5 posts, 0 answers
  1. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 06 May Link to this post

    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.

  2. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 06 May Link to this post

    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?

     

  3. UI for WPF is Visual Studio 2017 Ready
  4. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 11 May Link to this post

    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.
  5. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 11 May Link to this post

    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

  6. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 13 May Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready