본문 바로가기
VB.net/DataGridView

데이터 그리드뷰 셀에 숫자만 입력되게 하기

by 호야호잇 2018. 10. 12.


    Private Sub TextBox_keyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)


        If Char.IsDigit(CChar(CStr(e.KeyChar))) = False Then e.Handled = True


    End Sub


    Private Sub TextBox_keyPress1(ByVal sender As Object, ByVal e As KeyPressEventArgs)


        If Not (Char.IsDigit(CChar(CStr(e.KeyChar))) Or e.KeyChar = ".") Then e.Handled = True

    End Sub


    Private Sub Guide_DGV_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles Guide_DGV.EditingControlShowing

        MsgBox(Guide_DGV.CurrentCell.ColumnIndex)

        If Guide_DGV.CurrentCell.ColumnIndex = 2 Then

            AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress

        ElseIf Guide_DGV.CurrentCell.ColumnIndex = 1 Then

            AddHandler CType(e.Control, TextBox).KeyPress, AddressOf TextBox_keyPress1

        End If


    End Sub