Set valid data for datagridview cell

  • Thread starter Thread starter AbanoubZak
  • Start date Start date
A

AbanoubZak

Guest
Hello,

i have datagridview which have some numeric columns and others for prices.

i need to allow only some data to be inserted in these columns' cells

i have a code which used for normal text box

'97 - 122 = Ascii codes for simple letters
'65 - 90 = Ascii codes for capital letters
'48 - 57 = Ascii codes for numbers

If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If

and for prices

Dim allowed As String = "1234567890." & Chr(8)
If Not allowed.Contains(e.KeyChar) Then
e.Handled = True
Exit Sub
End If
If e.KeyChar = "."c Then
If TotalTB.Text.Contains("."c) Then
e.Handled = True
Exit Sub
End If
Else
If Not e.KeyChar = Chr(8) AndAlso TotalTB.Text.Contains("."c) Then
If TotalTB.Text.Length - 2 > TotalTB.Text.IndexOf("."c) Then
e.Handled = True
Exit Sub
End If
End If
End If
can i do somthing similar or close to that to these datagridview's cells?

Continue reading...
 
Back
Top