In this tutorial, you will learn how to use NumericInput mode for editing numeric data. C1TextBox and C1NumericEdit controls have a NumericInput property that is True by default. If the NumericInput property is set to True and DataType is a numeric type, the control functions in numeric mode facilitating typing of digits, decimal point and other numeric characters.
Control | Property | Value |
---|---|---|
Label1 | Text | Quantity: |
Label2 | Text | Discount: |
Label3 | Text | Unit Price: |
Label4 | Text | Scientific Number: |
Label5 | Text | Hexidecimal Number: |
Label6 | Text | CultureInfoSetup Event: |
Label7 | Text | Format: |
C1DbNavigator1 | Dock | Top |
Control | Property | Value |
---|---|---|
C1DbNavigator1 | DataSource | C1ExpressTable1 |
C1TextBox1 | DataSource | C1ExpressTable1 |
DataField | Quantity | |
C1NumericEdit1 | DataSource | C1ExpressTable1 |
DataField | Discount | |
C1TextBox2 | DataSource | C1ExpressTable1 |
DataField | UnitPrice |
There are several unbound (not bound to a data source) controls in the bottom part of the form. C1NumericEdit2 edits numbers in scientific format, with decimal point and exponent. This control also includes a drop-down calculator.
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TextBox3_ValueChanged( ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TextBox3.ValueChanged Try C1Label1.Value = C1TextBox3.Value Catch End Try End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TextBox3_ValueChanged(object sender, System.EventArgs e) { try { c1Label1.Value = c1TextBox3.Value; } catch { } } |
The C1TextBox4 control demonstrates how you can change number format by changing culture settings used in formatting. Set the DataType property to Int32
For example, we can show negative numbers with the word “minus” instead of the usual “-“. We will also suppress the fractional part of the number, and use “|” as thousands separator. We will also change the group sizes (so they are no longer thousands), make the first (rightmost) group contain one digit, second – two digits, third – three digits, and all the rest (higher) digits make a single group. This is done by the following event handler:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TextBox4_CultureInfoSetup(ByVal sender As Object, ByVal e As C1.Win.C1Input.CultureInfoSetupEventArgs) Handles C1TextBox4.CultureInfoSetup Dim ci As System.Globalization.CultureInfo = e.CultureInfo ci.NumberFormat.NegativeSign = " minus " ci.NumberFormat.NumberGroupSeparator = "|" ci.NumberFormat.NumberGroupSizes = New Integer() {1, 2, 3, 0} ci.NumberFormat.NumberDecimalDigits = 0 End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TextBox4_CultureInfoSetup(object sender, C1.Win.C1Input.CultureInfoSetupEventArgs e) { System.Globalization.CultureInfo ci = e.CultureInfo; ci.NumberFormat.NegativeSign = " minus "; ci.NumberFormat.NumberGroupSeparator = "|"; ci.NumberFormat.NumberGroupSizes = new int[] {1, 2, 3, 0}; ci.NumberFormat.NumberDecimalDigits = 0; } |
C1TextBox5 shows how to specify a custom, non-standard number format.
In this format, three colon-separated parts define three different formats used, correspondingly, for positive, negative numbers and zero. Character ‘0’ denotes a required digit, character ‘#’ specifies an optional digit, and ‘,’ is the thousands separator. Thousands separator on the right means the number is stored as times 1000 the entered number (per separator).
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TextBox5_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TextBox5.ValueChanged C1Label2.Value = C1TextBox5.Value End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TextBox5_ValueChanged(object sender, System.EventArgs e) { c1Label2.Value = c1TextBox5.Value; } |