Salve a tutti,
ho dei campi data in un datagridview e vorrei che man mano che scrivi la data apparissero da soli i trattini (o slash).
Il codice che ho creato è il seguente:
Ora, la prima sub, che devo ancora finire di implementare, serve per intercettare il tasto canc o delete, se nessuno di quei tasti è stato premuto e la cella ha 2 caratteri aggiungi lo slash. Se arriva a 5 (gg/mm) caratteri aggiunge l'altro slash.codice:Dim tasto As Integer = 0 Private Sub datagridview2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _ Handles DataGridView2.KeyDown If (e.KeyData = Keys.Delete) Then tasto = 1 End If If (e.KeyData = Keys.Cancel) Then tasto = 1 End If End Sub Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellValueChanged If DataGridView2.CurrentCell IsNot Nothing Then Label23.Text = DataGridView2.CurrentCell.Value 'DataGridView2.CurrentCell.Value = DataGridView2.CurrentCell.Value & "(" Dim stringa As String stringa = DataGridView2.CurrentCell.Value If ((stringa.Length = 2) And (tasto <> 1)) Then stringa = stringa & "/" DataGridView2.CurrentCell.Value = stringa End If End If End Sub
Il problema è che l'evento DataGridView2.CellValueChanged è verificato solo alla fine della modifica della cella, e quindi è inutile. Esiste un ecquivalente del TextBox.TextChanged per il datagridview (cioè che nota le modifiche in tempo reale) ?