ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Restricting Cell Navigation

The BeforeRowColChange event can be used to prevent the user from moving to a different cell, regardless of whether the current cell is modified. Set the Cancel argument to True to keep another cell from becoming current.

If the current cell has been modified, use the BeforeColUpdate event to examine its value before moving to another grid cell. If the value entered is invalid, set the Cancel argument to True to prevent the current cell from changing, and optionally beep or display an error message for the user. The BeforeColUpdate event provides a flexible way to validate user input and restrict cell navigation.

·      Visual Basic

Private Sub C1TrueDBGrid1_BeforeColUpdate(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs) Handles C1TrueDBGrid1.BeforeColUpdate

    Dim CharCode As Integer

    If e.ColIndex = 1 Then

 

        ' Data in Column 1 must start with upper case.

        CharCode = Asc(Me.C1TrueDBGrid1.Columns(1).Text)

        If CharCode > 64 And CharCode < 91 Then Exit Sub

       

        ' Display warning message for user.

        MessageBox.Show("Last name must start with upper case")

   

        ' Data validation fails, prohibit user from moving to another cell.

        e.Cancel = True

    End If

End Sub

·      C#

private void C1TrueDBGrid1_BeforeColUpdate( object sender,  C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)

{

    int CharCode;

    if ( e.ColIndex == 1 )

    {

        // Data in Column 1 must start with upper case.

        CharCode = this.C1TrueDBGrid1.Columns[1].Text[0];

        if ( CharCode > 64 && CharCode < 91 ) return;

 

        // Display warning message for user.

        MessagBox.Show("Last name must start with upper case");

 

        // Data validation fails, prohibit user from moving to another cell.

        e.Cancel = true;

    }

}

·      Delphi

procedure TWinForm.C1TrueDBGrid1_BeforeColUpdate(sender: System.Object; e: C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs);

var CharCode: Integer;

begin

  if (e.ColIndex = 1) then

  begin

 

    // Data in Column 1 must start with upper case.

    CharCode := Integer(this.C1TrueDBGrid1.Columns[1].Text[0]);

    if ( CharCode > 64 && CharCode < 91 ) then

      Exit;

   

    // Display warning message for user.

    MessageBox.Show('Last name must start with upper case');

   

    // Data validation fails, prohibit user from moving to another cell.

    e.Cancel = true;

  end;

end;


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