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.
Thanks Boris, that goes halfway to solving the problem.
But it needs to also handle the user entering negative numbers, or deleting the contents of the cell entirely (leaves " . " in cell). Both cause exceptions to be raised.
I can see how to handle the latter, but it's not so clear how to handle the user tabbing to the cell (text becomes selected) and then typing a negative number.
To make sure that we are on the same page here, I created a sample demonstrating the desired behavior as I am seeing it. Please review it and feel free to let me know if I misunderstood you or if you have any other questions.