Search code examples
c#winformsinfragistics

How do I detect a modification before the user closes the window


I am currently developing a C# Windows Form Application. I have a window with a table where you can edit some data and I would like to check if the user did something before to close the window. If he modified the data, we prompt a messagebox to ask him if he wants to save before closing the window. If he modified nothing or if he clicked on save button before we just close the window without any message.

As I start on C# I do not know if there is something to realize this. Maybe a kind of listener which detect any modifications and return a bool.

My save function returns a list with the data which have been modified, so I thought about call it and check if the list is empty or not. But It's maybe "heavy" to call the save function several times just to check is something changed.


Solution

  • Depends on what controls you have on the UI and how much flexible/dirty solution you need. One way is to capture change events (Text change, Cell Value change etc.) of different controls and keep a boolean flag to say something changed.