Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to identify the changes made to the form data?

How to identify the changes made to the form data?

Scheduled Pinned Locked Moved Windows Forms
csharpcsswinformstutorialquestion
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subrahmanyam K
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • S 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

      R Offline
      R Offline
      roel_v
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • R roel_v

        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

        S Offline
        S Offline
        Subrahmanyam K
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups