본문 바로가기
VB.net/DataGridView

DatagridView 이벤트 Numbers, Backspace & Delete 키 전용 VB.Net을 허용하려면

by 호야호잇 2018. 11. 9.
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
    Select Case DataGridView1.CurrentCell.ColumnIndex
        Case Is = 0, 1
            AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress
    End Select

End Sub

Private Sub TextBox_keyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
    If e.KeyChar <> ControlChars.Back Then
        e.Handled = Not (Char.IsDigit(e.KeyChar))
    End If
End Sub


만약안되면


디자인에서 아래 내용 적용


DataGridview EditMode 속성을 EditOnEnter로 변경