I am experiencing issued performing validation from the codebehind. My data is displayed in a datagrid. One of the columns (type) is a drop down and when the drop down menu is changed it triggers a DropDownClosed Event which is handled in the code behind.
What I am trying to achieve is to validate the content of the following column to match the newly selected type in the drop down. If it does not match i want a validation error to be displayed on the grid. I implemented my validation using the INotifyDataErrorInfo interface and it works really well except when I use it in the code behind. When the code behind calls the validation the ValidationSummary of the datagrid is never updated. What I am doing wrong here ??? When using the debugger I can clearly see the errors being added to the Errors dictionnary of the interface...
Here is the handler:
private void TypeBoxChanged(object sender, EventArgs e)
{
ComboBox box = (sender as ComboBox);
IncomingPolicy row = (IncomingPolicy)box.DataContext;
string ruleTypeValue = TypeList.GetKeyForText(box.SelectedItem.ToString());
//check if the type is the same
if(row.TypeWrapper == ruleTypeValue)
return;
if (row.ValidateRule(ruleTypeValue))
{
//SAVE the record
}
else
{
row.RaiseErrorsChanged("RuleWrapper");
}
}
The validate rule method will based on the ruletypevalue call this method
public bool ValidateRegularExpression(string property, string value, string expression, string errorMessage)
{
bool isValid = true;
Regex regex = new Regex(expression);
Match match = regex.Match(value);
if (match.Success)
{
RemoveError(property, errorMessage);
}
else
{
AddError(property, errorMessage, false);
isValid = false;
}
return isValid;
}
I followed the sample implementation on MSDN http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo%28VS.95%29.aspx