Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
If DataGridView1.CurrentCell.ColumnIndex = 2 Then
AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress
End If
End Sub
Private Sub TextBox_keyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If Char.IsDigit(CChar(CStr(e.KeyChar))) = False Then e.Handled = True
Dim str As String = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(DataGridView1.CurrentCell.ColumnIndex).Value
'null reference error here
End Sub
私はいくつかのことを試みましたが、それは常に私にnull参照エラーを与えます。EditingControlShowing
イベントでセルの値を取得しようとしたときも同じです。
このコードを試してください
Private Sub TextBox_keyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If Char.IsDigit(e.KeyChar) = False Then
e.Handled = True
Else
Dim str As String = CType(sender, TextBox).Text
'Do stuff
End If
End Sub
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加