DataForm Validation

4 posts, 1 answers
  1. Harald
    Harald avatar
    48 posts
    Member since:
    Oct 2013

    Posted 04 Oct 2015 Link to this post

    Hello,

    how can I prevent the user can exit the form?

    private void AddressDetails_ValidatingItem(object sender, System.ComponentModel.CancelEventArgs e)
            {
                Address address = this.AddressDetails.CurrentItem as Address;
                try
                {
                    if (address.LastName == null)
                    {
                        throw new ValidationException("Das Feld Nachname darf nicht leer sein.");
                    }
                    //Save Changes
                    SaveChanges();
                }
                catch (ValidationException ex)
                {
                   RadWindow.Alert(ex.Message);
                }  
            }

  2. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 07 Oct 2015 Link to this post

    Hi Harald,

    Can you please share some details on what exactly do you mean by exiting the form?

    Additionally, I suggest you taking a look at our documentation on Validation, as the supported by RadDataForm validation approaches are demonstrated in it. You may also find the DataForm Validation - ValidatingItem() useful on the matter.

    Regards,
    Stefan X1
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Harald
    Harald avatar
    48 posts
    Member since:
    Oct 2013

    Posted 11 Oct 2015 in reply to Stefan X1 Link to this post

    If a required field is empty, the Click on Commit-Button show a Alert and the User can´t leave the Editmode of the DataForm.
  5. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 14 Oct 2015 Link to this post

    Hi Harald,

    One way to achieve that is through the CancelEventArgs exposed by the ValidatingItem event. Just set the Cancel property to true:
    if (address.LastName == null)
        {
            throw new ValidationException("Das Feld Nachname darf nicht leer sein.");
            e.Cancel = true;
        }

    Hope this helps.

    Regards,
    Petya
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top