Let's say I want a column for entering decimal degrees for values between -180 and 180, with decimal place precision. I might set a column as:
column.MaskInput = "{double:-3.6}";column.MinValue = -180;column.MaxValue = 180;
However, when I enter a value like 180.1, I get an error message when the cell exits edit mode:
Data Error - Unable to update the data value: Input value does not satisfy maximum value constraint.
But why did the editor allow 180.1 to be entered in the first place? That breaks the maximum value?
How do I either prevent this, or stop that Data Error message displaying so that I can put my own validation in?
Thanks
Hello,
I believe that this is expected since the 'MaxValue' property is not actually restricting you from typing a greater value. It does not allow entering a greater value then the max one. So I tried to get the desired behavior through the following code sample:
private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { decimal n; bool isDecimal = Decimal.TryParse(e.Cell.GetText(Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw), out n); if (isDecimal) { if (e.Cell.Column.Key== "Decimal Column" && Convert.ToDecimal(e.Cell.GetText(Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw)) > Convert.ToDecimal(e.Cell.Column.MaxValue)) { e.Cell.Value = e.Cell.Column.MaxValue; e.Cell.SelStart = e.Cell.Text.IndexOf(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator); } } }
Please feel free to let me know if I misunderstood you or if you have any other questions.
Boris Toromanov"] I believe that this is expected since the 'MaxValue' property is not actually restricting you from typing a greater value. It does not allow entering a greater value then the max one.
I believe that this is expected since the 'MaxValue' property is not actually restricting you from typing a greater value. It does not allow entering a greater value then the max one.
Boris, in addition to my points in my reply, I don't think this is expected behaviour. For instance, with MaxValue as 180 and MaskInput as "{double:3.6}", try typing in 181. You'll notice that the control changes the value to 18.1 instead. That means the mask and the max value are being interpreted during a CellChange event (and that's without your code sample above).
So if, on cell change, the control modifies whole number values that are greater than max value, then surely it should be modifying the decimal values that are greater than the max value. Not doing so is inconsistent.
Anyway, any assistance you can give to resolve this would be much appreciated.
Hi again,
While you are in edit mode in a cell, the value is not changing when you are typing. The property which is actually changing is the text 'property'. When you step outside the cell, it is trying to interpret the text and to validate it, as it is if no errors exist. If the value is greater than the maximum or less than the minimum the value is not being updated and the 'CellDataError' is being fired. I tried to achieve the behavior you want in the above attached sample. Did you have the time to take a look at it and see if it meets your requirements? If not, please do so and let me know if that is not what you are after, I will be glad to assist you further.
Thanks Boris, but I still don't follow. First off, I think you need to read my other reply further up, where I try your code but find that it cannot handle entering negative numbers or deleting all text in a cell.
In all these scenarios, I am not exiting edit mode, i.e.:
I am just typing text into the cell, and at no point am I exiting edit mode. The validation is occuring on cell change.
When you say try your example, do you mean add the CellChange event to my code which includes the maxvalue and maskinput set on the column, as per my original post? Or are you saying to remove the maxvalue and maskinput and just use your CellChange instead?
Perhaps a complete sample is necessary?
Sorry, missed the complete sample post above. Will take a look now! Sorry for confusion.
Thanks Boris, the zipped sample explains the full story. Makes sense now.
One problem remains, that if you delete the contents completely and commit the row, the value is blank (null).
I've handled it in my code, but would be interested to see how you would handle it.
I am glad to hear that you were able to solve this. Could you please clear out what do you want to happen when the contents are deleted completely? If you want for example the cell to have 'Value' 0 - you could attach an 'else' statement after the first if ( "if (isDecimal)..." ) and do something like this:
if (isDecimal) { ...................... } else { e.Cell.Value = 0; }
Please let me know if that is what you are looking for, I hope it helps.
As I said, if you really worked at it, you might be able to use a DrawFilter to display scientific notations in a masked edit control, like UltraMaskEditor or UltraNumericEditor. But it doesn't make much difference which one you use, neither one has any support for editing scientific notation values. I guess you might be able to come up with a mask that would allow the user to enter the data as a string, but it won't work as a number, I don't think.
Personally, I would probably use a TextEditor and then just try to validate the data in code, rather than trying to enforce a mask.
Dear Mike (and all) --
Would some kind of masked edit control (if is there one of those in the kit?) work for entering and displaying scientific notation?
Or could we (should we) make a custom textbox kind of thing that will validate and handle both standard-notation and scientific-notation input and display?
Thoughts?
Please advise.
(BTW, I am sorry but you might see another thread that I opened on this topic, I apologize for cross-posting, I just thought it deserved its own thread.)
Thanks.
-- Mark Kamoski
Hi Mark,
I don't think so. Do you want to just display it, or also edit? If you worked at it, you might be able to get the numeric editor to display scientific notation, but I don't think it will ever let the user edit in that format.
Is there a way to get the UltraNumericEditor to display scientific notation?
Hi,
Thank you for sharing this. I see now, your approach seems to be the right one to me.
Please do not hesitate to ask if something comes up, I will be very happy to help.