ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

C1TrueDBGrid.BeforeColEdit Event

Occurs before a cell enters edit mode.

[Visual Basic]

Public Event BeforeColEdit As BeforeColEditEventHandler

[C#]

public event BeforeColEditEventHandler BeforeColEdit

[Delphi]

public property BeforeColEdit: BeforeColEditEventHandler read remove_BeforeColEdit write add_BeforeColEdit;

Example

Assume a Boolean field called Done exists, and its C1DataColumn.NumberFormat property is set to specify Yes/No as the display format. Further assume that, when the user presses Y or N, the cell contents change immediately instead of entering edit mode. This process is accomplished in BeforeColEdit as follows:

·      Visual Basic

       Private Sub C1TrueDBGrid1_BeforeColEdit(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.BeforeColEditEventArgs) Handles C1TrueDBGrid1.BeforeColEdit

           With Me.C1TrueDBGrid1.Columns(e.ColIndex)

               ' If this isn't the "Done" column, or if the user clicked with the mouse, then simply continue.

               If .DataField <> "Done" Or e.KeyChar = Chr(0) Then

                   Exit Sub

               ' Cancel normal editing and set the field to the proper result based upon KeyAscii. Beep if an invalid character was typed.

               e.Cancel = True

               Select Case UCase(e.KeyChar)

                   Case "Y"

                       .Value = -1

                   Case "N"

                       .Value = 0

                   Case Else

                       Beep()

               End Select

           End With

       End Sub

·      C#

       private void c1TrueDBGrid1_BeforeColEdit(object sender, C1.Win.C1TrueDBGrid.BeforeColEditEventArgs e)

       {

           C1.Win.C1DataColumn col = e.Column.DataColumn;

           // If this isn't the "Done" column, or if the user clicked with the mouse, then simply continue.

           if (col.DataField != "Done" || e.KeyChar == 0 )

           {

               return;

           }

           // Cancel normal editing and set the field to the proper result based upon KeyAscii. Beep if an invalid character was typed.

           e.Cancel = true;

           switch (e.KeyChar. .ToUpper())

           {

               case "Y";

                   Col.Value = -1;

                   break;

               case "N";

                   Col.Value = 0;

               default:;

                   Beep();

           }

       }

·      Delphi

       procedure TWinForm.c1TrueDBGrid1_BeforeColEdit(sender: System.Object; e: C1.Win.C1TrueDBGrid.BeforeColEditEventArgs);

       begin 

         with Self.C1TrueDBGrid1.Columns[e.ColIndex] do

         begin

           // If this isn't the 'Done' column, or if the user clicked with the mouse, then simply continue.

           if (DataField <> 'Done') Or (e.KeyChar = Char(0)) Then

             Exit;

           // Cancel normal editing and set the field to the proper result based upon KeyAscii. Beep if an invalid character was typed.

           e.Cancel := True;

           if (char.ToUpper(e.KeyChar) = 'Y') then

             Value := -1;

           else if (char.ToUpper(e.KeyChar) = 'N') then

             Value := 0;

         end;

       end;

For details on the BeforeColEdit event, see the Changing Cell Contents with a Single Keystroke topic.

See Also

C1TrueDBGrid Class | C1TrueDBGrid Members | C1.Win.C1TrueDBGrid Namespace


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.