I have a DataGridView that has some columns marked as ReadOnly.  I
don't want the user to be able to enter the ReadOnly columns.
(Significantly speeds up data entry.) Instead I want when they leave a
field or enter a ReadOnly field that the focus skip to the next non-
ReadOnly field.

Here is the problem code:

 Private Sub OpenItemsGrid_CellEnter(ByVal sender As Object, ByVal e
As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView_OpenItems.CellEnter
    If Not bInitializing AndAlso DataGridView_OpenItems.CurrentCell
IsNot Nothing AndAlso DataGridView_OpenItems.CurrentCell.ReadOnly Then
      Try
        SendKeys.Send("{TAB}")
      Catch ex As NullReferenceException
        ' Suppress the error
      Catch ex As Exception
        WriteException(ex)
      End Try
    End If
  End Sub

The problem: SendKeys.Send("{TAB}") line is regularly throwing a
NullReferenceException and complains that "Object reference not set to
an instance of an object."

I can't set the DataGridView.CurrentCell property because it trips an
InvalidOperationException, "Operation is not valid because it results
in a reentrant call to the SetCurrentCellAddressCore function."

Anyone have a suggestion on how I can get the behavior I want?

- R.B. Davidson.

Reply via email to