In UltraNumericEditor ,
i have the MinValue=0 and MaxValue=100
NumericType=double
but it allows me to enter upto 100.99
how to resrict that to 100.00
Well as I explained in my previous post, the EditorWithMask can't make the assumption that the user didn't intend to alter the decimal portion of the control before changing the integer portion, so it won't arbitrarily stop the key press at this point.
You might be able to prevent the key from being pressed during the KeyDown event, but this will be difficult to do since I don't think there's an easy way to tell where the cursor is positioned. You could try casting the Editor to an EditorWithMask and looping through the DisplayChars in the Sections to find where the cursor is (by using the SelectionStart + SelectionLength properties), but you would still have to manually parse each section's value to see if it would exceed the maximum.
I wrote up a quick test function to do this that you can modify to suit your needs. This does seem to prevent editing the fraction portion if the value is already at the MaxValue. If you need to alter this to suit your particular situation, at least that main portion of iterating through the sections is illustrated.
private void ultraNumericEditor1_KeyDown(object sender, KeyEventArgs e){ // Only do this check for numeric values if ((e.KeyValue >= 48 && e.KeyValue <= 57) || (e.KeyValue >= 96 && e.KeyValue <= 105)) { EditorWithMask editor = (EditorWithMask)this.ultraNumericEditor1.Editor; int cursorPosition = editor.SelectionStart + editor.SelectionLength; int currentPosition = 0; foreach (SectionBase section in editor.Sections) { if (currentPosition + section.DisplayChars.Count < cursorPosition) { currentPosition += section.DisplayChars.Count; continue; } // We know the cursor is in this section, so process now if (section is FractionPart) { // If we're editing the decimal section, then check the current text to see if we'd go above the maximum string currentText = editor.GetText(MaskMode.Raw); if (double.Parse(currentText) >= Convert.ToDouble(this.ultraNumericEditor1.MaxValue)) { e.SuppressKeyPress = true; return; } } } }}
-Matt
Yes you are right,Am not able to exit from edit mode.
But why to allow them to enter more than 100.00
As it is not allowing me to enter 101 or more than 100.99.
Here it should not allow me to enter 100.99 too.
Problem i have faced.
By mistake i enter 100.01 in that UltraNumericEditor and i was trying to click out of that control.
but i was not able to click any where on the page.
I was strucked there.
and after analysing i chaged the value of that control.
but we cant expect the same from the end user
Hope u would understand the situation
I'm assuming that the control is not letting you exit edit mode, or lose focus, with a value of 100.99. If so, this is the expected behavior with the mask controls because it is not possible to determine if the user was editing the decimal portion with the intent of changing the integer portion afterwards. For example, the user might already have 100 as the value and decide to type in ".99", then afterwards change the 100 to 50.