How to identify the changes made to the form data?
-
Hi, I have the following requirement (Windows Forms in C#). I have a form with data populated for differnet types of controls (say textbox, checkbox, grid etc). If the user makes some changes to the state of any controls (say edit the values from the textboxes, change chekbox state, Radio button state etc) and now then the user tries to close the form without saving the changes made to the form (By clicking the SAVE or OK button on that form). In that case, I should warn/remind the user that some changes have been made to the form data and were not saved/committed. How could I achieve the above requirement without having to implement the follng ways? 1. Take a member variable and to update it whenever some changes were made to the controls using their all possible event handlers. 2. Looping through all the controls to find the changes. Thanks in advance for some suggestions.
Subrahmanyam K
-
Hi, I have the following requirement (Windows Forms in C#). I have a form with data populated for differnet types of controls (say textbox, checkbox, grid etc). If the user makes some changes to the state of any controls (say edit the values from the textboxes, change chekbox state, Radio button state etc) and now then the user tries to close the form without saving the changes made to the form (By clicking the SAVE or OK button on that form). In that case, I should warn/remind the user that some changes have been made to the form data and were not saved/committed. How could I achieve the above requirement without having to implement the follng ways? 1. Take a member variable and to update it whenever some changes were made to the controls using their all possible event handlers. 2. Looping through all the controls to find the changes. Thanks in advance for some suggestions.
Subrahmanyam K
If your controls are bound to an underlying business object, you could use a IsDirty property on that business object. In all the set {} accessors of each property of your business object you then set the m_dirty member variable to true, like: public string MyProperty { get { return m_myProperty; } set { if (m_myProperty != value) { m_myProperty = value; m_isDirty = true; } } Then, to save the data, you can just call the Save() method on your business object and let the business object figure out whether anything needs to be persisted to the database. Roel
-
If your controls are bound to an underlying business object, you could use a IsDirty property on that business object. In all the set {} accessors of each property of your business object you then set the m_dirty member variable to true, like: public string MyProperty { get { return m_myProperty; } set { if (m_myProperty != value) { m_myProperty = value; m_isDirty = true; } } Then, to save the data, you can just call the Save() method on your business object and let the business object figure out whether anything needs to be persisted to the database. Roel
Thank You very much Roel. I'm using Typed datasets in my Application. I think the HasChanges() method of the dataset can be used to find for any changes and then commit them to the database. Thanks.
Subrahmanyam K