DataGridView Numeric Only Cell?

前端 未结 8 652
广开言路
广开言路 2021-01-06 07:33

I am new to winforms..I am trying to set two column of DataGridView to Numeric Only.. I do not want user to be able to type anything into a cell unless its a natural number

8条回答
  •  青春惊慌失措
    2021-01-06 07:50

    Try This with lambda

    Private Sub dgv_pararelhp_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgv_pararelhp.EditingControlShowing
        If dgv_pararelhp.CurrentCell.ColumnIndex = 0 Then'// change this optional your index column.
             AddHandler CType(e.Control, TextBox).KeyPress, Sub(s_, e_)
                                                                If Char.IsDigit(CChar(CStr(e_.KeyChar))) = False Then e_.Handled = True
                                                             End Sub
           End If
    End Sub
    

提交回复
热议问题