In this tutorial, you will learn how to use C1ExpressTable events to customize data behavior in code.
Number of Components | Name | Namespace |
---|---|---|
1 C1ExpressTable | C1ExpressTable1 | C1.Data.Express.C1ExpressTable |
1 C1TrueDBGrid | C1TrueDBGrid1 | C1.Win.C1TrueDBGrid.C1TrueDBGrid |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1ExpressTable1_BeforeFieldChange _ (ByVal sender As Object, ByVal e As C1.Data.FieldChangeEventArgs) Handles _ C1ExpressTable1.BeforeFieldChange If e.Field.Name = "Quantity" Then If e.NewValue < 1 Then e.NewValue = 1 End If ElseIf e.Field.Name = "Discount" Then If e.NewValue < 0 Or e.NewValue > 1 Then Throw New ApplicationException("Discount must be between 0 and 1") End If End If End Sub Private Sub C1ExpressTable1_BeforeEndEdit _ (ByVal sender As Object, ByVal e As C1.Data.RowChangeEventArgs) Handles _ C1ExpressTable1.BeforeEndEdit If e.Row("Quantity") * e.Row("UnitPrice") > 100000 Then Throw New ApplicationException("Too expensive") End If End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1ExpressTable1_BeforeFieldChange (object sender, C1.Data.FieldChangeEventArgs e) { if (e.Field.Name == "Quantity") { if ((short)e.NewValue < 1) e.NewValue = (short)1; } else if (e.Field.Name == "Discount") { if ((float)e.NewValue < 0 || (float)e.NewValue > 1) throw new ApplicationException("Discount must be between 0 and 1"); } } private void c1ExpressTable1_BeforeEndEdit (object sender, C1.Data.RowChangeEventArgs e) { if ((short)e.Row["Quantity"] * (decimal)e.Row["UnitPrice"] > 100000) throw new ApplicationException("Too expensive"); } |