I have a datagridview (dgvSalesOrderLines ) that has 5 columns. The types are:
decimal | character | character | decimal | decimal
I am trying to get it so if the user adds a new row that for columns 0, 3 and 4 that only numeric / decimal data is allowed. The following works the first column but after that nothing works.
Looking for any help on this.
Thanks.
Code:Private Sub dgvSalesOrderLines_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvSalesOrderLines.EditingControlShowing Dim iCurCol As Integer = dgvSalesOrderLines.CurrentCell.ColumnIndex Select Case iCurCol Case 0, 3, 4 'only allow numerics If TypeOf e.Control Is TextBox Then Dim tb As TextBox = TryCast(e.Control, TextBox) AddHandler tb.KeyPress, AddressOf dgv_KeyPress End If Case Else End Select End Sub Private Sub dgv_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) If Not (Char.IsNumber(e.KeyChar)) Then e.Handled = True End If End Sub




Reply With Quote