This tutorial demonstrates some options in formatting and parsing data.
Control | Property | Value |
---|---|---|
C1Label1 | TextDetached | True |
Text | Date: | |
C1Label3 | TextDetached | True |
Text | Discontinued: | |
C1Label4 | TextDetached | True |
Text | Order Details | |
C1Label5 | TextDetached | True |
Text | Unit Price: | |
C1Labe6 | TextDetached | True |
Text | Discount: | |
C1Label7 | TextDetached | True |
Text | Quantity: | |
RadioButton1 | Name | rbYesNo |
Text | Yes/No | |
Checked | True | |
RadioButton2 | Name | rbTrueFalse |
Text | True/False | |
RadioButton3 | Name | rbOnOff |
Text | On/Off | |
RadioButton4 | Name | rbOneZero |
Text | 1/0 | |
RadioButton5 | Name | rbCustom |
Text | Custom (Yep/Nope) | |
Button1 | Name | btnClose |
Text | Close |
Control | Property | Value |
---|---|---|
C1ExpressTable1 | ConnectionComponent | C1ExpressConnection1 |
DbTableName | Products | |
C1ExpressTable2 | ConnectionComponent | C1ExpressConnection1 |
DbTableName | Order Details |
Now, create a master-detail relation between C1ExpressTable1 (master) and C1ExpressTable2 (detail):
Control | Property | Value |
---|---|---|
C1DbNavigator1 | DataSource | C1ExpressConnection1 |
DataMember | _Products | |
C1DbNavigator2 | DataSource | C1ExpressConnection1 |
DataMember | _Products.Products - Order_Details | |
C1Label2 | DataSource | C1ExpressConnection1 |
DataField | _Products.ProductName | |
C1TextBox2 | DataSource | C1ExpressConnection1 |
DataField | _Products.Discontinued | |
C1TextBox3 | DataSource | C1ExpressConnection1 |
DataField | _Products.Products - Order_Details.UnitPrice | |
C1TextBox4 | DataSource | C1ExpressConnection1 |
DataField | _Products.Products - Order_Details.Discount | |
C1TextBox5 | DataSource | C1ExpressConnection1 |
DataField | _Products.Products - Order_Details.Quantity | |
C1Label8 | DataSource | C1ExpressConnection1 |
DataField | _Products.Products - Order_Details.Quantity |
This will be the default format of the C1TextBox2 control, but we will also make provisions for a custom format, setting the CustomFormat property of the C1TextBox2 control to Yep|Nope. This custom format will be enabled when the FormatType property is set to CustomFormat, which will be done with option buttons in the next step.
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub rbYesNo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbYesNo.Click Me.C1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.YesNo End Sub Private Sub rbTrueFalse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbTrueFalse.Click Me.C1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.TrueFalse End Sub Private Sub rbOnOff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbOnOff.Click Me.C1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.OnOff End Sub Private Sub rbOneZero_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbOneZero.Click Me.C1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.Integer End Sub Private Sub rbCustom_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbCustom.Click Me.C1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.CustomFormat End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void radioButton_Click(object sender, System.EventArgs e) { switch (((RadioButton)sender).Name) { case "rbYesNo": this.c1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.YesNo; break; case "rbTrueFalse": this.c1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.TrueFalse; break; case "rbOnOff": this.c1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.OnOff; break; case "rbOneZero": this.c1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.Integer; break; case "rbCustom": this.c1TextBox2.FormatType = C1.Win.C1Input.FormatTypeEnum.CustomFormat; break; } } |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1Label8_Formatting(ByVal sender As Object, ByVal e As C1.Win.C1Input.FormatEventArgs) Handles C1Label8.Formatting e.Text = e.Value.ToString() + " (base10)" End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void C1Label8_Formatting(object sender, C1.Win.C1Input.FormatEventArgs e) { e.Text = e.Value.ToString() + " (base10)"; } |
In the C1TextBox1 control we will show how you can allow entering dates in multiple formats. Complete the following tasks:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.C1TextBox1.Value = DateTime.Now End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void Form1_Load(object sender, System.EventArgs e) { this.c1TextBox1.Value = DateTime.Now; } |
Control | Property | Value |
---|---|---|
C1TextBox1 | DateTimeInput | False |
FormatType | CustomFormat | |
CustomFormat | MM/dd/yyyy|d-MMM-yyyy|d.M.yy |
This is a list of allowed formats separated with '|'. Parsing an input string, all formats will be tried until a matching one is found. Formatting values for display, we obviously need a single format, so only the first format will be used for formatting.
We also want the control to display the date in LongDate format when not in focus.
Now the control shows its date value in long format when not in focus, in the first short format when in focus, and the user can type data in any of the three allowed sort formats.