This is a migrated thread and some comments may be shown as answers.

RadComboBox with ValidateOnDataError (MVVM)

2 Answers 86 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dario
Top achievements
Rank 2
Dario asked on 25 Mar 2013, 04:54 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Vladi
Telerik team
answered on 28 Mar 2013, 09:46 AM
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.

0
Dario
Top achievements
Rank 2
answered on 28 Mar 2013, 09:57 AM
Thank you for support.
Tags
ComboBox
Asked by
Dario
Top achievements
Rank 2
Answers by
Vladi
Telerik team
Dario
Top achievements
Rank 2
Share this question
or