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.
What version of the controls are you using? Are you using the latest Hot Fix? If not, I suggest you download it and see if that helps. I'm pretty sure this issue was fixed a while ago.
If that does not help, then you should Submit an incident to Infragistics Developer Support so they can check this out. Clearly, if the control recognizes the correct MinValue/MaxValue when you try to tab out of it, but not when you are spinning the value, then that's a bug and needs to be corrected.
Thanks for the suggestion Mike. We are using 8.2.20082.1000.
I'll give it a try with the latest version. If it doesn't work I'll submit an incident pointing to this topic.
I submitted an incident to support, and the problem is harder than I thought. Under the presence of a DataFilter that converts values to and from the same datatype, plus Min and Max constraints the validation of the control breaks. That's a very uncommon scenario and I don't think there will be a solution for the time being.
I decided to go back to the drawing board. These are the requirements:
As mentioned before, my first approach was deriving a control from the UltraNumericEditor and assign a DataFilter to do the conversion, but the Min and Max validation doesn't work.
I'm open to other ideas.
If you are deriving from the control, anyway, maybe you can just override the Value property and convert the units there?
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.