The item indexer never gets called so that the error icon won't ever get shown in the cell. Since the .Error() method gets called the row error icon does show.
What is missing to enable the grid to call my indexer method show it will show the error?
In my form/user control i am setting up the grid:'
_radioItemsGrid.AutoGenerateColumns = false; _options.RadioButtons = new List<RadioButtonItem>(); var bs = new BindingSource(_options.RadioButtons, null); _radioItemsGrid.DataSource = bs; errorProvider1.DataSource = _radioItemsGrid.DataSource;
Here is my biz class
public class RadioButtonItem : IDataErrorInfo
{
public string Label
{
get { return _label; }
set
{
if (_label != value)
{
_label = value;
if(string.IsNullOrWhiteSpace(value))
SetError(nameof(Label), "Label is required");
}
}
}
public string ModelExpression
{
get { return _modelExpression; }
set
{
if (_modelExpression != value)
{
_modelExpression = value.Clean();
if (string.IsNullOrWhiteSpace(value))
SetError(nameof(ModelExpression), "Model Expression is required");
}
}
}
public string Error => _errors.Any() ? string.Join(Environment.NewLine, _errors.Select(e => e.Value).ToArray()) : "";
private void SetError(string columnName, string errorMessage)
{
if(_errors.ContainsKey(columnName))
_errors[columnName] = errorMessage;
else
_errors.Add(columnName, errorMessage);
}
private Dictionary<string, string> _errors = new Dictionary<string, string>();
private string _label;
private string _modelExpression;
public string this[string columnName]
{
get
{
if (_errors.ContainsKey(columnName))
return _errors[columnName];
return string.Empty;
}
}thanks!