Hello,
I created a "UOMEditor" control that inherits from the UltraNumericEditor.
Based on the user preferences, the control displays length in inches or millimiters. So, when the database stores a value of 1 and the user has the system configured to "English System", the control displays "1.00 in". If the user prefers the "Metric System", the control displays "25.4 mm", but the database always stores 1.
I implemented this by applying a DataFilter on my UOMEditor. If the current configuration is Metric System, the value is multiplied by 25.4 when the conversion direction is OwnerToEditor and divides by 25.4 when the direction is EditorToOwner.
The conversion works fine, but I'm having a problem with the MinValue and MaxValue. In the attached sample project the default measure system is English. The MinValue is 1 and the MaxValue is 100. Th UOMEditor displays 1.00 inches.
If you change the UOM value with the up and down arrows, the maximum value is 100, and the minimum is 1. So far so good because this is the trivial case where there is no conversion involved.
Now change the measure system to Metric. The UOM changes to 25.4 mm. The Minvalue and MaxValue are always represented in inches, so they remain at 1 and 100.
Now change the UOM value with the up arrow key. The maximum value is 100, which is wrong. It should be 2540 (100 inches * 25.4 mm/inches). Now decrease the value with the down arrow key. The minimum value is 1, which is also wrong. It should be 25.4 (1 inches *25.4 mm/inches). Keep the vaue of 1.00 in the editor and tab out. The control won't let you unless the value is 25.4 or more. That means the internal validation works as expected and it converts the displayed value from 25.4 to 1.00 before comparing it to the minimum value of 1.00.
To sum it up, the internal validation when tabbing out of the control works as expected, but the validation when the editor text changes doesn't.
Is there a way to alter the min and max value validation process when the text changes?
Thanks.
Thanks for your help Mike. This issue has been solved.
For the stand alone editor I'm using the "MyValue" approach.
For the grid I'm using the unbounded column approach.
Hi,
First, I want to apologize for all the confusion here. It looks like this approach will not work, either, since the grid is going to bypass the editor and get the value directly through the UIElements when the cell is not in edit mode.
So, I've come up with another solution that I am sure will work and I've tested it myself to make sure.
Basically, the idea is to use an unbound column instead of a DataFilter. So you no longer need to derive your own editor class. What you do is hide the real Age column in the grid and add a new, unbound age column to display to the user. You use the InitializeRow event to take the value in the Age column, multiply it by 10 and then assign that value to the unbound age. You reverse this process in the AfterCellUpdate so that when the user makes a change to unbound age, the age column gets the new value divided by 10.
I've updated your sample and I am attaching it here so you can see the code.
The standalone control is working fine now using the MyValue idea. Thanks for that one.
For the grid I extended an editor from EditorWithMask and overrode the Value property:
public override object Value{ get { int value = (int)base.Value; int retVal = value / 10; return retVal; } set { int newValue = (int)value; base.Value = newValue*10; }}
However that's not giving me the expected behavior. Run the attached project for more information. When the data is first displayed the conversion is not happening (that's wrong). If I change the Age column to 200, when I tab out the displayed value changes to 20 (that is wrong) and the business object property is set to 20 (which is correct).
I'm looking into the implementation of EditorWithMask to find answers. Any help you can provide is greatly appreciated.
For the Standalone control, use another property like MyValue.
In the case of the grid, the grid doesn't really use the control, anyway, the control simply provides an editor to the grid for it's own use. So what you could do in that case is derive an editor from EditorWithMask (which is what the UltraNumericEditor uses) and override the Value on that. I checked to make sure and the Value property on EditorWithMask is virtual.
The UltraNumericEditor.Value property is not virtual so there's no way to override it.
Support suggested creating a secondary property "MyValue" and do the conversion in there, but then the control won't work as an EditorControl on a grid column, which only deals with the Value property.