Decimal Values are not allow in DGV

  • Thread starter Thread starter kachani_anil
  • Start date Start date
K

kachani_anil

Guest
HI,

I set some function key for numerical value only in some of my DGV cells but it allows me to only 0-9 characters it does not allow me to write decimal values. here are code


plz provide suggestion to correct these

Public Class clsfunction
Public con As New SqlClient.SqlConnection(My.Settings.AgrasenConnectionString)
Public cmd As New SqlClient.SqlCommand
Dim Numstr As String = "0123456789.-/"
Public Sub keyPressNumeric(ByVal pflag As Boolean, ByVal e As KeyPressEventArgs)
If pflag = True Then
If Not IsNumeric(e.KeyChar.ToString) And Not e.KeyChar = Chr(Keys.Back) Then
e.Handled = True
End If
ElseIf pflag = False Then
If IsNumeric(e.KeyChar.ToString) Then e.Handled = True
End If

End Sub
Public Sub KeyPressNumeric(ByVal e As KeyPressEventArgs)
If Not IsNumeric(e.KeyChar.ToString) And Not e.KeyChar = Chr(Keys.Back) Then
e.Handled = True

End If
End Sub

Public Sub KeyPressNonNumeric(ByVal e As KeyPressEventArgs)
If IsNumeric(e.KeyChar.ToString) Then e.Handled = True


End Sub


-----------------------------------------------------------------------


Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing

If Me.DataGridView1.CurrentCell.ColumnIndex = 6 Or Me.DataGridView1.CurrentCell.ColumnIndex = 7 Or Me.DataGridView1.CurrentCell.ColumnIndex = 9 Or Me.DataGridView1.CurrentCell.ColumnIndex = 11 Then
Dim txtNum As TextBox = e.Control
RemoveHandler txtNum.KeyPress, AddressOf keypress_gridviewcell
AddHandler txtNum.KeyPress, AddressOf keypress_gridviewcell
Else
'Dim ctrl As Control = e.Control
'If (ctrl.GetType) Is GetType(TextBox) Then
Dim txtNum As TextBox = e.Control
RemoveHandler txtNum.KeyPress, AddressOf keypress_gridviewcell
End If

'End If
End Sub

Continue reading...
 
Back
Top