RadComboBox with ValidateOnDataError (MVVM)

3 posts, 1 answers
  1. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 25 Mar 2013 Link to this post

    Hi to all,
    I have a RadComboBox controlo that has 

    SelectedItem={Binding MyItemSelected, ValidatesOnDataError=True, Mode=TwoWay}

    MyViewModel has "ViewModelBase" class linked that keep "Error System"

    public class ViewModelBase : INotifyPropertyChanged, IDataErrorInfo
        {
            #region private variables
     
            private bool _hasErrors;
             
            #endregion
     
            #region public properties
     
            public bool HasErrors
            {
                get { return _hasErrors; }
                set
                {
                    _hasErrors = value;
                    NotifyPropertyChanged("HasErrors");
     
                }
            }
     
            #endregion
     
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            protected void NotifyPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this,
                    new PropertyChangedEventArgs(propertyName));
                }
     
                //Aggiorna lo stato di errore dell'intera entità
                if (propertyName != "HasErrors")
                    HasErrors = (_dataErrors.Count > 0);
            }
            #endregion
     
            #region IDataErrorInfo Members
            private string _dataError = string.Empty;
            string IDataErrorInfo.Error
            {
                get { return _dataError; }
            }
            protected Dictionary<string, string> _dataErrors = new Dictionary<string, string>();
     
            string IDataErrorInfo.this[string columnName]
            {
                get
                {
                    if (_dataErrors.ContainsKey(columnName))
                        return _dataErrors[columnName];
                    else
                        return null;
                }
            }
     
            protected void UpdateError(string columnName, string errorMessage)
            {
                _dataErrors[columnName] = errorMessage;
            }
     
            protected void RemoveErrors(string columnName)
            {
                if (_dataErrors.ContainsKey(columnName))
                    _dataErrors.Remove(columnName);
            }
     
            #endregion
        }

    If I use this method with a TextBox control, I obtain correctly "classic red waring", but with RadComboBox not appears nothing.
    How can I keep this case?
  2. Answer
    Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 28 Mar 2013 Link to this post

    Hi Dario,

    In order to achieve validation when using RadComboBox I would suggest you to see our online demo that demonstrates how to achieve the desired behavior.

    The online demo is available here.

    All the best,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 28 Mar 2013 Link to this post

    Thank you for support.
Back to Top