Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/07/2008, 03:11
Analyzer
 
Fecha de Ingreso: febrero-2005
Mensajes: 37
Antigüedad: 19 años, 9 meses
Puntos: 0
Respuesta: Escape sobre fila de datagrid

Código:
   1.
      '______________________________________________________________________________________________________________
   2.
      '
   3.
      '  Class:     CustomDataGridView
   4.
      '  Author:    Sean Fackrell
   5.
      '  Date:      24/02/2006
   6.
      '______________________________________________________________________________________________________________
   7.
      '
   8.
      '  Notes:     Wrapper class for DataGridView to correct error when using Escape key on first row
   9.
      '______________________________________________________________________________________________________________
  10.
      Public Class CustomDataGridView
  11.
        Inherits DataGridView
  12.
       
  13.
        '  Need an event so that calling form can cancel the edit using the binding source
  14.
        Public Event EscapeOnFirstRowPressed()
  15.
       
  16.
        '______________________________________________________________________________________________________________
  17.
        '
  18.
        '  Function:  ProcessDataGridViewKey
  19.
        '  Author:    Sean Fackrell
  20.
        '  Date:      24/02/2006
  21.
        '______________________________________________________________________________________________________________
  22.
        '
  23.
        '  Params:    e KeyEventArgs - same signature as DataGridView.KeyEventArgs
  24.
        '______________________________________________________________________________________________________________
  25.
        '
  26.
        '  Notes:     Fix for problem with the DataGridView in .NET framework v2.0.50727
  27.
        '             When user cancels an edit on the first row of a SQL Server bound DataGridView
  28.
        '             after raising the DataError event, the DataGridView tries to add a new row and
  29.
        '             creates an unhandled exception.
  30.
        '______________________________________________________________________________________________________________
  31.
        Protected Overrides Function ProcessDataGridViewKey(ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
  32.
       
  33.
          If e.KeyCode = Keys.Escape AndAlso (Me.NewRowIndex = 1 And Me.RowCount = 2) Then
  34.
            '  Only take action when user is trying to cancel the first row edit
  35.
            e.Handled = True
  36.
            RaiseEvent EscapeOnFirstRowPressed()
  37.
          Else
  38.
            '  Don't pass on keystroke to base DataGridView class because this causes the error
  39.
            MyBase.ProcessDataGridViewKey(e)
  40.
          End If
  41.
       
  42.
        End Function
  43.
       
  44.
      End Class