Basically I have a few hundred controls that on LostFocus need to update different variables located in a class.
Private Sub txtFirstName_LostFocus(sender As Object, e As System.EventArgs) Handles txtFirstNameMain.LostFocus
Interview.FIRSTNAME = txtFirstNameMain.Text
End Sub
Private Sub txtLastName_LostFocus(sender As Object, e As System.EventArgs) Handles txtLastNameMain.LostFocus
Interview.LASTNAME = txtLastNameMain.Text
End Sub
Is there a way to create a single Sub that can handle this? Maybe I can put the target variable on the tag of the control? But then how would I reference said variable without a lot of code work?
Private Sub Lost_Focus_UpdateClass(sender As TextBox, e As System.EventArgs) Handles txtFirstNameMain.LostFocus, txtLastNameMain.LostFocus
Select Case sender.Tag
Case "FIRSTNAME"
Interview.FIRSTNAME = sender.Text
Case "LASTNAME"
Interview.LASTNAME = sender.Text
End Select
End Sub
This just feels like it takes too much for what it does. Is there a better way to handle this?
I'm using WinForms.
EDIT: TnTinMn - Worked. Had to make an alteration for null-able fields.
Me.tbFirstName.DataBindings.Add("Text", dataStore, "FirstName", True, DataSourceUpdateMode.OnValidation, String.Empty)
Me.tbLastName.DataBindings.Add("Text", dataStore, "LastName", True, DataSourceUpdateMode.OnValidation, String.Empty)