Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have an application that i want to when closing prompt the user with the question if they want to save changes yes or no. And if yes save the changes. However if the user just opened the application and pulled up a certain record, but made no changes and begun to close the application, I do not want it to prompt them with that question. So if they made changes prompt them with the question if there are no changes don't prompt. Any help would be greatly appreciated. By the way the program is written in VB.NET.
  • Leaders
Posted
So, when the user makes a change, you set a boolean to True. Then in the Form Closing, ask if the user wants to save changes only if the boolean is true. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

True

 

Yes this is true but how in the form do I determine if the user has made a change? The form as many textboxes and is using a tab control with each tab populated with different controls, what determininant factor to set the boolean equal to true?

Posted

Try using the TextBox.Validating Event event and either

 

 

make a control that derives from the TextBox Class and add a property such as 'TextChanged' that retuns a boolean if the text changed, the textbox will need to know what it's original text was so I would make it have only 1 constructor with 1 parameter, a string, that is supposed to be the original text. Doing this will probably be more efficient and you don't nee to use the Validating Event.

 

 

- or -

 

Using some type of hashtable that stores the texbox's id, and the original text of the textbox, listen to the Validating Event, and compare the text with what was in the hashtable, and you'll know if the text changed or not.

  • *Experts*
Posted

Back to Iceplug's post, make a Boolean variable like dataModified in your form's declaration section. When opening a new file or saving the current file set dataModified to False. Then in all the events that add, edit or in anyway modify the current data set dataModified to True.

 

Then in your form's closing event add

   Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       If dataModified Then
           e.Cancel = True 'keep the form open
           'pop up a message box asking to save changes
       End If
   End Sub

 

From the message box's DialogResult:

If Yes then save the data and change dataModified to False and close

If No then change dataModified to False and close

If Cancel then do nothing

 

This is about the simplest way to do it.

 

'opps I re-read your post and I think that you already know this.....sorry.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...