dyarosh
asked on
How to determine if data on a form has been modified using Visual Basic
I am new to Visual Basic and have learned mainly from Trial and Error. I definitely don't do things the way they are supposed (at least that is what I think.) Here is my problem. I have a windows form that displays a datagrid of employees. When the user double clicks on an employee it opens another form where the data can be modified. The way I accomplish this is to have a check for an employee id on the form that gets set from the first form (employeeid). Using the employeeid, I use the following code to load the record onto the form (see EmployeeLoad Event code). Now what I want to do is to see if any changes have been made to the record before allowing the form to be closed (see CancelAddButton_Click code).
I never get the Prompt to Save data message. When debugging, EmployeeDrow.RowState always says Unchanged. What am I doing wrong?
I never get the Prompt to Save data message. When debugging, EmployeeDrow.RowState always says Unchanged. What am I doing wrong?
EmployeeLoad Event
Me.EmployeesTableAdapter.FillByEmployeeWithEmployeeID(pfmsDataSet1.Employees, EmployeeIDText.Text)
If pfmsDataSet1.Employees.Count = 1 Then
EmployeeDrow = pfmsDataSet1.Employees.Rows(0) ' EmployeeDrow is a global variable
Else
MsgBox("More than 1 employee found")
End If
===========================================================================
CancelAddButton_Click code
If EmployeeDrow.RowState = DataRowState.Modified Then
MsgBox("Prompt to save data")
Else
Me.Close()
End If
ASKER
Modified CancelAddButton_Click to the following:
If pfmsDataSet1.HasChanges() Then
MsgBox("prompt to save')
End If
Me.Close
I still don't get the prompt.
If pfmsDataSet1.HasChanges() Then
MsgBox("prompt to save')
End If
Me.Close
I still don't get the prompt.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
pfmsDataSet1.AcceptChanges () did not work. Since the data is bound on the form I used EmployeesBindingSource.End Edit() and now I get prompted when the data is changed. Thanks for your help.
Wayne