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. DataSet HasChanges doesn't pick up changes made by bound TextBoxes

DataSet HasChanges doesn't pick up changes made by bound TextBoxes

Scheduled Pinned Locked Moved Windows Forms
csharpdotnetwpfwcfquestion
7 Posts 3 Posters 0 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.
  • R Offline
    R Offline
    rtklueh
    wrote on last edited by
    #1

    I've seen this question in various forms in several places, but I have yet to see a satisfactory solution. Using .Net Framework 2, I've got a DataSet with elements bound to several TextBoxes which are scattered on several tab pages on a form. I can then change any of the TextBox texts, and the corresponding changes do appear in the DataSet. I want to enable an Apply button when any of these elements have changed. I tried to use the DataSet's HasChanges, but it will not return a 'true'. I also tried a RowChanged event on one of the DataTables in the DataSet, but it never triggered. I tried to resort to using the TextChanged event from all the TextBoxes. That almost works, but the event is raised when the binding initially sets the TextBox contents. I can tolerate that on the first tab page of my form, but the TextBoxes on the other tab pages don't get set until you initially select those tabs, and it is difficult to distinguish between a user-initiated change and the original setting. Thanks for your suggestions.

    M 1 Reply Last reply
    0
    • R rtklueh

      I've seen this question in various forms in several places, but I have yet to see a satisfactory solution. Using .Net Framework 2, I've got a DataSet with elements bound to several TextBoxes which are scattered on several tab pages on a form. I can then change any of the TextBox texts, and the corresponding changes do appear in the DataSet. I want to enable an Apply button when any of these elements have changed. I tried to use the DataSet's HasChanges, but it will not return a 'true'. I also tried a RowChanged event on one of the DataTables in the DataSet, but it never triggered. I tried to resort to using the TextChanged event from all the TextBoxes. That almost works, but the event is raised when the binding initially sets the TextBox contents. I can tolerate that on the first tab page of my form, but the TextBoxes on the other tab pages don't get set until you initially select those tabs, and it is difficult to distinguish between a user-initiated change and the original setting. Thanks for your suggestions.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      This is what I do. Have form level boolean bLoading instantiated to True, do your binding in the formloading event, the last thing in the formload event is to set bLoading to false and turn off the save button. bLoading can also be used to short circuit the combo selection events and any selected index change events during the loading by putting If bLoading then Exit Sub/function in the event method.

      Never underestimate the power of human stupidity RAH

      R 1 Reply Last reply
      0
      • M Mycroft Holmes

        This is what I do. Have form level boolean bLoading instantiated to True, do your binding in the formloading event, the last thing in the formload event is to set bLoading to false and turn off the save button. bLoading can also be used to short circuit the combo selection events and any selected index change events during the loading by putting If bLoading then Exit Sub/function in the event method.

        Never underestimate the power of human stupidity RAH

        R Offline
        R Offline
        rtklueh
        wrote on last edited by
        #3

        I think I am actually doing the equivalent. I'm loading the DataSet in formload, and then I disable the 'apply' button (or 'save', etc). Then, any subsequent edits of the TextBoxes will raise their TextChanged events and I can then enable 'apply'. The problem shows up on the additional tab-pages that I have on the form. Their TextBoxes don't seem to receive the bound data until the user clicks on the tab-page, and this raises their TextChanged events. And this seems to occur after the tab-page's Enter event is raised, so I can't find a good place to re-disable the 'apply'.

        S M 2 Replies Last reply
        0
        • R rtklueh

          I think I am actually doing the equivalent. I'm loading the DataSet in formload, and then I disable the 'apply' button (or 'save', etc). Then, any subsequent edits of the TextBoxes will raise their TextChanged events and I can then enable 'apply'. The problem shows up on the additional tab-pages that I have on the form. Their TextBoxes don't seem to receive the bound data until the user clicks on the tab-page, and this raises their TextChanged events. And this seems to occur after the tab-page's Enter event is raised, so I can't find a good place to re-disable the 'apply'.

          S Offline
          S Offline
          sixadOne
          wrote on last edited by
          #4

          Don't know if it works, but maybe you can fire the load/enter event of each tabpages when the form is loading. All bindings should have been done after that. Or you can have a boolean for each tabpages that determines if it's the firs load or not. Not very good solutions. It's a shame you can't use events related to your datasource.

          1 Reply Last reply
          0
          • R rtklueh

            I think I am actually doing the equivalent. I'm loading the DataSet in formload, and then I disable the 'apply' button (or 'save', etc). Then, any subsequent edits of the TextBoxes will raise their TextChanged events and I can then enable 'apply'. The problem shows up on the additional tab-pages that I have on the form. Their TextBoxes don't seem to receive the bound data until the user clicks on the tab-page, and this raises their TextChanged events. And this seems to occur after the tab-page's Enter event is raised, so I can't find a good place to re-disable the 'apply'.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            rtklueh wrote:

            Their TextBoxes don't seem to receive the bound data until the user clicks on the tab-page,

            Interesting, I have never actually bound 1 record to multiple tab pages, I must try this to verify the event sequence. As seven suggested you could use the tab changeindex to manage the button state but it is ugly.

            Never underestimate the power of human stupidity RAH

            R 1 Reply Last reply
            0
            • M Mycroft Holmes

              rtklueh wrote:

              Their TextBoxes don't seem to receive the bound data until the user clicks on the tab-page,

              Interesting, I have never actually bound 1 record to multiple tab pages, I must try this to verify the event sequence. As seven suggested you could use the tab changeindex to manage the button state but it is ugly.

              Never underestimate the power of human stupidity RAH

              R Offline
              R Offline
              rtklueh
              wrote on last edited by
              #6

              I think it's strange that I wrote my own control, sort of an editable list control thing (I don't like the DataGrid), and it seems to set the DataSet HasChanged properly (I think because my control does BeginEdit and EndEdit). I don't understand why the TextBox doesn't do as well? Like the English guy with the vacuum cleaner says, 'things just ought to work properly'.

              R 1 Reply Last reply
              0
              • R rtklueh

                I think it's strange that I wrote my own control, sort of an editable list control thing (I don't like the DataGrid), and it seems to set the DataSet HasChanged properly (I think because my control does BeginEdit and EndEdit). I don't understand why the TextBox doesn't do as well? Like the English guy with the vacuum cleaner says, 'things just ought to work properly'.

                R Offline
                R Offline
                rtklueh
                wrote on last edited by
                #7

                Thanks everybody for the comments. It looks like the 'Enter' event for each of the tab pages occurs before the controls on that page are updated from the DataSource. And it looks like the 'SelectedIndexChanged' from the tab control occurs after the updating. So, I can set a flag while any of the pages are being updated and ignore any of the 'changed' events from any of the controls during that time. Not too pretty, but it seems to do the job.

                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