Cell validation and localization

2 posts, 0 answers
  1. Kornelije
    Kornelije avatar
    28 posts
    Member since:
    May 2011

    Posted 06 Jul 2012 Link to this post

    I have a business object with three columns (int year, int month and double value) bound to the GridView.

    When the user adds a new row or edits an existing one, some cell validation takes place. 

    This is an example property of the business object

    private int month;
    public int Month
    {
        get
        {
            return month;
        }
        set
        {
            try
            {
                if (month == value)
                    return;
      
                month = value;
                Time = new DateTime(t.Year, value, t.Day, t.Hour, t.Minute, t.Second);  
      
                onPropertyChanged("Month");
      
            }
            catch
            {
                throw new InvalidOperationException(Strings.MonthInvalid);
            }
        }
    }

    When the user enters 13 or something else that is not a valid month number, the "new DateTime()" call will throw an exception which will be caught, and then in turn, a new exception will be thrown and the message will be shown to the user in a nice red tooltip.

    However, if I enter something like 1354684635135746876510, the control will be unable to fit that into my integer property so the Exception with the message "Input is not in a correct format" will be thrown. The message is in English, and I need to localize this. Obviously I can't edit .NET's exceptions (nor should I). But how can I solve this? I'd like to be able to validate the cells with my own messages supplied, no matter what is entered. Is this possible?

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Jul 2012 Link to this post

    Hello Kornelije,

    I would recommend you to run through this blog post for a reference. 

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top