[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

VB.net - prompting user if they want to save changes

Hi
I've an application with many inputs (split across multiple user defined controls).

When the user tries to exit, I'd like to prompt them if they want to save changes (this part is ok, its knowing if they've made changes before prompting is the part I need to know how to do)

Is there an easy way to know if user has made changes - rather than record every controls original value , and then check through every control if the value has been changed when the user wants to exit?

Thanks in advance
0
rwallacej
Asked:
rwallacej
2 Solutions
 
dctuckCommented:
When I do this, I have a private Boolean variable called something like IsChanged, which I then set each time a value of a control changes.

For things like textboxes and comboboxes and the likes, I create a method called something like ValueChanged which handles the TextBox.TextChanged and ComboBox.SelectedIndexChange events for each control I need to check. That way, you don't have to check each individual one - the one method does it for them all.
0
 
rwallacejAuthor Commented:
thanks, this seems to work - I'll get back later and award points if nothing comes up
0
 
SanclerCommented:
If the controls are bound to a dataset/datatable then you can check that to see if there are changes

    'make sure any changes from the control/s are committed to the datasource ... details depend on the binding/s
    BindingContext(myDataSource).EndCurrentEdit
    If myDataSet.HasChanges Then
        'your warning, and response, code goes here
        MsgBox("Changes made")
    End If

or, if any datatable/s are not in a dataset

    'make sure any changes from the control/s are committed to the datasource ... details depend on the binding/s
    BindingContext(myDataSource).EndCurrentEdit
    Dim dr() As DataRow = myTable.GetChanges
    If Not dr Is Nothing Then
        'your warning, and response, code goes here
        MsgBox("Changes made")
    End If

for each datatable.

Roger
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now