Skip to main content Skip to footer

HowTo : Set Number Range in C1Input Controls

C1TextBox is the main data bound control used for entering and editing information in a text form. It not only supports data formatting for all data types, including special features for date-time formats but also supports edit mask, data validation and other features. C1NumericEdit is another data bound control that is derived from C1TextBox and is specialized for editing numeric values. When a value is entered in a C1TextBox/C1NumericEdit control, the input string undergoes several transition phases before it becomes a typed value of theValue property.

Implementation

In this blog, we will discuss one of the commonly asked user-scenario wherein it is required to allow the user to enter only numeric values that fall between the range of -99.99 to 99.99 without loosing the focus from the control. It is like setting the MinValue/Maxvalue property for the C1Input Control. Since, the validation has to be done when the user is entering the value, the LostFocus event cannot be used. The solution is to validate the value either in the TextChanged event. The idea is to set the EditMask property of the C1Input controls on the basis of the first character entered by the end-user. If the character entered is a number, then the EditMask property is set to '00.00' and if the first character is a symbol ('-'), then the EditMask property is set to '#00.00'. On adding the following code in the TextChanged event, the user will be allowed to enter the number within the permitted range only.



private void c1TextBox1_TextChanged(object sender, EventArgs e)  
{  
      C1.Win.C1Input.C1TextBox t1 = (C1.Win.C1Input.C1TextBox)sender;  
      if (t1.Text[0] == '-')  
      {  
           t1.EditMask = "#00.00";  
      }  
      else if (t1.Text[0] == '_')  
      {  
           t1.EditMask = "#";  
      }  
      else  
      {  
           t1.EditMask = "00.00";  
      }  
}

For complete implementation, please refer to the attached sample. Download VB Sample Download CSharp Sample

MESCIUS inc.

comments powered by Disqus