In this tutorial, you will learn how to use edit mask to facilitate and restrict user input.
Control | Property | Value |
---|---|---|
Label1 | Name | labStoredExpNumber |
Text | <stored value> | |
Label2 | Name | labStoredDateTime |
Text | <stored value> | |
Label3 | Name | labStoredPhone |
Text | <stored value> | |
Label4 | Name | labStoredMultiline |
Text | <stored value> | |
C1Label1 | Name | labCompanyName |
Text | labCompanyName | |
C1Label2 | Name | labCustomerID |
Text | labCustomerID | |
C1Label3 | Name | labOrderDate |
Text | labOrderDate | |
C1Label4 | Name | labFreight |
Text | labFreight | |
Button1 | Name | btnClose |
Text | Close |
Control | Property | Value |
---|---|---|
C1ExpressTable1 | ConnectionComponent | C1ExpressConnection1 |
DbTableName | Customers | |
C1ExpressTable2 | ConnectionComponent | C1ExpressConnection1 |
DbTableName | Orders | |
C1ExpressTable3 | ConnectionComponent | C1ExpressConnection1 |
DbTableName |
<Composite…>
* See steps below. |
* Selecting the <Composite…> value for the C1ExpressTable3 opens the Composite Table Editor. In the editor, complete the following steps:
Control | Property | Value |
---|---|---|
C1DbNavigator1 | DataSource | C1ExpressConnection1 |
DataMember | CompositeTable | |
labCompanyName | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.CompanyName | |
labCustomerID | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.CustomerID | |
labOrderDate | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.OrderDate | |
labFreight | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.Freight | |
C1TextBox5 | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.CustomerID | |
C1TextBox6 | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.OrderDate | |
C1TextBox7 | DataSource | C1ExpressConnection1 |
DataField | CompositeTable.Freight |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TextBox1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TextBox1.ValueChanged Try labStoredExpNumber.Text = CType(Me.C1TextBox1.Value, String) Catch labStoredExpNumber.Text = "" End Try End Sub Private Sub C1TextBox2_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TextBox2.ValueChanged Try labStoredDateTime.Text = CType(Me.C1TextBox2.Value, String) Catch labStoredDateTime.Text = "" End Try End Sub Private Sub C1TextBox3_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TextBox3.ValueChanged Try labStoredPhone.Text = CType(Me.C1TextBox3.Value, String) Catch labStoredPhone.Text = "" End Try End Sub Private Sub C1TextBox4_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles C1TextBox4.ValueChanged Try labStoredMultiline.Text = CType(Me.C1TextBox4.Value, String) Catch labStoredMultiline.Text = "" End Try End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TextBox1_ValueChanged(object sender, System.EventArgs e) { try { labStoredExpNumber.Text = (string)this.c1TextBox1.Value; } catch { labStoredExpNumber.Text = ""; } } private void c1TextBox2_ValueChanged(object sender, System.EventArgs e) { try { labStoredDateTime.Text = (string)this.c1TextBox1.Value; } catch { labStoredDateTime.Text = ""; } } private void c1TextBox3_ValueChanged(object sender, System.EventArgs e) { try { labStoredPhone.Text = (string)this.c1TextBox1.Value; } catch { labStoredPhone.Text = ""; } } private void c1TextBox4_ValueChanged(object sender, System.EventArgs e) { try { labStoredMultiline.Text = (string)this.c1TextBox1.Value; } catch { labStoredMultiline.Text = ""; } } |
Here '#' is an optional position for a digit or sign, '9' is an optional position for a digit, '0' is a required position for a digit, '!' is a special character specifying right justification for the following text, '^' cancels right justification mode, 'e' – a literal.
There are two new special characters used in this mask: '>' causes the next characters to be converted to upper case, 'P' is a non-standard special character (custom placeholder) allowing entering either 'A' or 'P'.
Property | Value |
---|---|
Placeholder | P |
LookupChars | AP |
Thus the letter 'P' represents a position in edit mask where the user can type 'A' or 'P'.
To enable this storage format, set SaveBlanks to True and SaveLiterals to False (both properties are contained in MaskInfo). Also, change StoredEmptyChar from default '_' to '*' to store asterisk in blank positions. If you set SaveBlanks to False, SaveLiterals to True, blank positions will not be saved in the database, the above data will be saved as "11/8/2002 1:42PM".
For the C1TextBox4:
"First Name: "CCCCCCCCCCCCCCC\n"Last Name: "CCCCCCCCCCCCCCCCCCCC\n"
Date of Birth: "!90/90/9900^\n"Work Status: "CCCCCCCCCCCCCCC\n"Salary:
$"!######0.^99
Here ‘\n’ represents a line break.
This ensures that all positions left blank by the user are saved as spaces. If SaveBlanks is set to False, optional positions not filled by the user will be ignored. Additionally, you can set SaveLiterals to False, which will prevent saving literal texts, so only the information typed by the user is saved.
Control | Property | Value |
---|---|---|
labCustomerID | MaskInfo.EditMask | >LLLLL |
C1TextBox5 | EditMask | >LLLLL |
labOrderDate | FormatType | CustomFormat |
CustomFormat | M/d/yyyy | |
MaskInfo.EditMask | !90/90/0000 | |
C1TextBox6 | FormatType | CustomFormat |
CustomFormat | M/d/yyyy | |
EditMask | !90/90/0000 | |
labFreight | FormatType | CustomFormat |
CustomFormat | $ ####0.## | |
MaskInfo.EditMask | $ !99990.^99 | |
C1TextBox7 | FormatType | CustomFormat |
CustomFormat | $ ####0.## | |
EditMask | $ !99990.^99 |