Torna al Thread
Public Class dgv_modificato
Inherits System.Windows.Forms.DataGridView
Dim riga As Integer
Dim colonna As Integer
Dim asd As DataGridViewCellValidatingEventArgs
Protected Function non_so(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
asd = e
Return (e)
End Function
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
Select Case colonna
Case 0
Select Case keyData
Case 48 To 57, 8
Me.Rows(riga).ErrorText = ""
dataGridView1_CellValidating(Me, asd)
Case Else
Me.Rows(riga).ErrorText = "sono ammessi solo numeri!!!"
msg = Nothing
End Select
End Select
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Private Sub dataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As DataGridViewCellCancelEventArgs) Handles Me.CellBeginEdit
riga = e.RowIndex
colonna = e.ColumnIndex
End Sub
Private Sub dataGridView1_CellValidating(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
Select Case colonna
Case 1
Me.Rows(e.RowIndex).ErrorText = ""
Dim Data As Date = Date.Today.ToString("dd/MM/yyyy")
If Me.Rows(e.RowIndex).IsNewRow Then Return
If Not Date.TryParse(e.FormattedValue.ToString(), Data) Then
Me.Rows(e.RowIndex).ErrorText = "La data deve essere nel formato ""dd/MM/yyyy"""
e.Cancel = True
End If
End Select
End Sub
End Class