Another technique for updating an unbound column is to use the AfterColUpdate event to adjust the value of other (bound) columns. For example, imagine a pair of columns for Debit and Credit, as shown in this portion of a grid display:
Assume that there is no database field for these, but that they are unbound columns that derive their value from a single Balance column, which is either positive or negative. From the user's perspective, it would be desirable to edit these values directly. From your perspective, it would be desirable to have the grid update the dependent Balance column automatically.
True DBGrid for WinForms makes such tasks easy. The following code would be put in the grid's AfterColUpdate event to cause either column to change the Balance column when updated:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TrueDBGrid1_AfterColUpdate(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.ColEventArgs) Handles C1TrueDBGrid1.AfterColUpdate Dim row as Integer = Me.C1TrueDBGrid1.Row Me.C1TrueDBGrid1(row, "Balance") = -e.Column.DataColumn.Value End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void C1TrueDBGrid1_AfterColUpdate(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e) { int row = this.c1TrueDBGrid1.Row; this.c1TrueDBGrid1[row, "Balance"] = -e.Column.DataColumn.Value; } |
Notice that, when updating these columns, the code actually changes the value of the Balance column, which is both bound and invisible.