I need to update an employee record on a database and I have 2 forms to do that.
The 1st form shows a grid with a list of some employees, the user has the choice to right click on a record an opt for adding a new employee or changing or deleting an existing employee. If the user opts to create a new employee I am showing a 2nd form with all the empty fields for an employee master. If the user opts for changing or deleting an employee record I will show the same 2nd form with all populated employee fields.
The scenario described above is a very common when you want to update a record on
a table, normally you do not update directly on the grid instead you use a second form where
you will show all fields related to the record you want to update and be able to validate the data before saving the changes to the database.
On Form1 I am passing the Selected Employee Id on the Grid (if any) and the Maintenance Action (Create, Change or Delete) to 2 properties previously defined in Form2
(if Action Create is selected the variable is passed empty, for the others I am passing the Id on the clicked record). Then I am showing Form 2 without closing Form1.
Form 1
Sub ShowChildForm()
form2.strEmployeeId
form2.strAction
form2.Show()
End Sub
// Activated event
Form1_Activated
if strAction1 = "Done"
Refresh grid here
endif
End Sub
On form Form2 I will update the Database using a Table Adapter and
pass back to form1 a value "Done" in a property defined in Form1 meaning that I need to refresh the Grid because a record has been added, changed or deleted. If not action was completed I don't need to refresh the grid. Finally I close Form2 and the Focus goes back to Form1 which was left open behind Form2.
Form 2
Private button_Save_Click()
dtaTable.Update(dtsTable, myTable)
Form1.strAction1 = "Done"
me.close
End Sub
Now on the Activated Event of Form1 I am checking if the passed value is equal to "Done"
so I can refresh the Grid. But after doing a debug I noticed that the program goes to the Activated Event a lot of times which is not efficient. I can using a variable to control that, so the refresh is made only once on the Activated event but still the variable checking will be done many times. Is there any other more efficient way to accomplish this or maybe a most modern technique in VS Basic 2012.
The scenario described above is a very common scenario when you want to update a record on
a table, normally you do not update directly on the grid instead you use a second form where
you will show all fields related to the record you want to maintain and be able to validate the data before saving the changes to the database.
Thanks in advance