We have what I would think would be a simple problem but I can't find a discussion on the topic anywhere. On our form, we have an editable child collection that is bound to a DataGridView that allows additions and modifications within the grid. One of the child properties is a quantity field that we would like to return a double. With the attribute as a double, the following error is returned when changing the attribute value in the grid.
The following exception occurred in the DataGridView:
System.InvalidCastException: Unable to cast object of type 'system.Double' to type 'System.String'.
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) ....
Changing the attribute to return a string instead of a double resolves the problem so we have a work around. Using the BindingSourceRefresh control did not resolve the problem either.
Found the line that caused the problem but still don't understand what's happening. Here's the property definition:
public Double quantity{ set{CanWriteProperty(
true); if (_quantity != value){_quantity =
value; PropertyHasChanged();}
}
}
Removing the call to PropertyHasChanged resolved the problem as well. Any ideas?
ID10T error.
ValidationRules.AddRules(CommonRules.StringRequired, "quantity"); was the problem.
Copyright (c) Marimer LLC