How to show Validation Error Message for UserControls

2 posts, 0 answers
  1. Maurizio
    Maurizio avatar
    43 posts
    Member since:
    Jan 2012

    Posted 01 Jul 2014 Link to this post

    I'm using a UserControl to show and edit a specific property in RadPropertyGrid. In the setter of the property I throw a ValidationException if the user has entered some invalid value. The property looks like this:

    public int MyProperty
    {
        get { return _MyProperty; }
        set
        {
            if (value == -1)
                throw new ValidationException("My Validation error message");
     
            ...  
        }
    }

    It the user enters -1 a nice red frame appears around the UserControl in the PropertyGrid cell, but no Validation Tooltip!!!

    If I use e. g. a Textbox to display data, there is a red validation Tooltip. How can I achieve this for my custom controls?

    I don't like the the approach with a CustomValidationAttribute, because just throwing a ValidationException is much more straightforward...

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Jul 2014 Link to this post

    Hi Peter,

    Generally, when you create some custom UserControl for editing, you will most probably need to implement the validation ToolTip on your own and be responsible for its bindings and display. I guess you will get the same behavior no matter if it is placed inside RadPropertyGrid, DataForm, RadGridView, Microsoft DataGrid, etc. 
    However, everything depends on your exact scenario. Does the editing pass through a TextBox for example that has built-in validation ToolTip ? Is there a kind of toolTip implemented in your editing control ?


    Regards,
    Maya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top