Salve vorrei sapere se cè un modo per intercettare gli eventi dei controlli solo con una sub sola
nel mio esempio:
codice:
Private Sub Modifica(ByVal query As String)
Dim command1 As New OleDb.OleDbCommand(query, OleDbConnection1)
command1.Connection.Open()
command1.ExecuteNonQuery()
command1.Connection.Close()
DataGrid1.Update()
command1 = Nothing
End Sub
Private Sub Textbox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
If cambia = 1 Then
Dim query = "UPDATE clienti SET denominazione='" + TextBox4.Text + "' WHERE cod = " + TextBox2.Text
Modifica(query)
End If
cambia = 0
End Sub
Private Sub Textbox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
If cambia = 1 Then
Dim query = "UPDATE clienti SET indirizzo_fatt='" + TextBox5.Text + "' WHERE cod = " + TextBox2.Text
Modifica(query)
End If
cambia = 0
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles TextBox5.KeyPress
cambia = 1
End Sub
In questo modo che faccio dovrei scrivere la sub keypress per ogni controllo quindi texbox4, texbox5,
dato che devo fare la stessa cosa in ogni sub : cambia = 1
vorrei sapere se cè un modo per scrivere meno codice.
Grazie a tutti.