Solved

What event to use to determine changes were made on a form?

Posted on 2015-01-20
5
65 Views
Last Modified: 2015-01-21
I'm not sure the best way to do this but I want to incorporate functionality that when a user makes any changes to any data and then tries to exit/close the form without saving the changes, I want to be able to prompt them with a message letting them know this. I don't believe the TextChanged event would work because that would get flagged every time you just select a record to edit or view. What about the Validated Event?

Thanks!
0
Comment
Question by:BlakeMcKenna
  • 2
  • 2
5 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40560693
Microsoft does not implemented a way to inform you that data has change over time so that you can inform the user that there is data on the form that has not yet been saved. If you want such functionality you must implement it yourself. What you can do is set a Boolean data type variable and every time the user changes a variable that needs to be saved to update the Boolean to true and before closing the form check the state of that variable. You will also need to set this variable to false every time you save the data so that the variable correctly reflects the true state of the form's data.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40560698
Hi Fernando,

That's actually what I'm doing now...kinda old school. I just wondered if there was an Event that could be utilized for this purpose. Oh well, I'll keep doing it the old way.

Thanks!
0
 
LVL 40
ID: 40563278
This is how I do it, in a way that makes it easier to change the variable (_hasChanged). Note the Handles at the right of the event method declaration. This is the list of all the controls that contains information that needs to be saved in the database. I can thus set the variable from a unique point instead of doing it from many different places in the Form.
	Private Sub Type_Changed(sender As Object, e As EventArgs) Handles cboLocal.TextChanged, txtPlural.TextChanged, txtType.TextChanged, chkBuyUnit.CheckedChanged, chkList.CheckedChanged, chkManual.CheckedChanged, chkPerishable.CheckedChanged, chkSpecialLocation.CheckedChanged, chkWarning.CheckedChanged
		_hasChanged = True
	End Sub

Open in new window

0
 

Author Comment

by:BlakeMcKenna
ID: 40563319
James,

Did you declare Type using WithEvents?
0
 
LVL 40
ID: 40563716
Type is not declared, it is simply the name I gave to the method because the data comes from a Type table in the database.

Contrary to what many think, because that was the case in classic VB, the name of an event method does not matter. Call it ji67vL_oifje78 or ab if you want. What makes the method an event is the Handles at the end of the declaration. They are what really matters. The signature (parameters type) must also be of the right type for the events that you want to trap.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now