Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, January 7, 2010 5:34 AM
hi all.
in my winform app i have several data entry forms which are not binded.(for some reasons)
when the user will click "Close" button, i would like to check if data has been changed and then ask him if he want to save before exit.
whats the best way to do this?shachar
All replies (7)
Thursday, January 7, 2010 6:10 AM ✅Answered
I am assuming you have some textbox and rih text box etc in your form where user changes the data. Now textbox/rich textbox has an event notification of TextChanged.
One of the approach you can use is have a flag in your application i.e. bool value which is set true if the data is changed. Now when user changes any text in the textbox, the TextChanged notification is sent and it sets the bool value to true. Once you save the data you can set the flag to false.
So lets say, i open the form and do some changes. You app would set the flag to true. I would then press close. You app checks this flag and seeing it set to true warns me data will be lost and want to save etc.
Hope this helps.
Incase you have radio buttons etc in your form which user can change, same way use the state change notification and set the flag to true.Kavitesh Singh.
Thursday, January 7, 2010 1:37 PM ✅Answered
You would declare a variable in the top of your Form class (something like bool DataChaged) then in each text box's TextChanged event you would set the DataChanged variable to true.
In the click event of your close button you would check to see if DataChanged = true. If it is true you would let the user know to see if they want to save the changes. You might also want to put something in your FormClcosing event as well since the user might be able to close the form without using your Close button if the ControlBox is visible on the form. One word of caution on this though is if the user clicks your close button and you show them the message you need to set the DataChanged variable back to false after you handle it and before you call the Close method on the form.
I think this will help with your problem.
Dewayne Dodd - Landshark Software "Please make sure to 'Mark As Answer' if this answer solves your question"
Thursday, January 7, 2010 5:59 AM | 1 vote
Hi,
Put some flag in the text box key press event .when the form closing event check the flag .pop up the message for save .hope it helpsBest Regards, C.Gnanadurai Please mark the post as answer if it is helpfull to you
Thursday, January 7, 2010 6:28 AM | 1 vote
hi all.
in my winform app i have several data entry forms which are not binded.(for some reasons)
when the user will click "Close" button, i would like to check if data has been changed and then ask him if he want to save before exit.
whats the best way to do this? shachar
Are you wanting to check on each specific form that is closed or the main application? Is the "close" button on the main form or the data entry forms?
-Scosby
Thursday, January 7, 2010 11:42 AM
for each form....shachar
Thursday, January 7, 2010 12:04 PM | 1 vote
1) Create One Form Level Variable
2) Check the Form Keypress Event And Form Mouse Event , if any valid key enters update that variable
3)When form closed , check that variable for either it has a value or not
Happy Coding, RDRaja
Thursday, January 7, 2010 12:07 PM | 1 vote
I would make a panel that will appear if any data were to be changed.
I don't know if you have a registration form for the users to fill out, but if you have and it has a "are these the right data" function that the user can view before accepting, then you just add the same procedure to your "Close" button IF there is any changes.