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. C#
  4. Databindings Question

Databindings Question

Scheduled Pinned Locked Moved C#
helpdatabasewpfwinformswcf
3 Posts 2 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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    I'm programming a windows forms application that retrieves information from a database, binds it to various controls(datagrids, textboxes, datetimepickers,etc.). The binding happens correctly and saving and loading work just fine. An issue, however, has arisen in the need to catch the form before it closes to ask the user if they want to save. Just catching the event and calling the save function if the user wants to save works, but I'm looking for a way to check the data before the dialog box pops, and suppressing the box from showing if there have been no changes. I see this as being potentially doable from one of two places: Within my handler class, which houses the database and the appropriate saving and loading functionality, as well as exposing the tables to the other classes. Within the BindingSource elements(there are about a dozen). The problem is, that I don't see any event or member in each one that I can handle or check to see if the data is different from the original. I tried using a set of foreach loops that loops through every table in the dataset, every row in the table, and checking the RowState parameter, but they remain UnModified, because I don't call EndEdit() on the bindingsources (because I don't think I should do that until I'm actually saving). Obviously, I could handle the Changed event on each control that I bindto, and set a boolean to true anytime after binding, but that seems very overkill and it seems like there should be an easier/better/more efficent way.

    E 1 Reply Last reply
    0
    • D Drew McGhie

      I'm programming a windows forms application that retrieves information from a database, binds it to various controls(datagrids, textboxes, datetimepickers,etc.). The binding happens correctly and saving and loading work just fine. An issue, however, has arisen in the need to catch the form before it closes to ask the user if they want to save. Just catching the event and calling the save function if the user wants to save works, but I'm looking for a way to check the data before the dialog box pops, and suppressing the box from showing if there have been no changes. I see this as being potentially doable from one of two places: Within my handler class, which houses the database and the appropriate saving and loading functionality, as well as exposing the tables to the other classes. Within the BindingSource elements(there are about a dozen). The problem is, that I don't see any event or member in each one that I can handle or check to see if the data is different from the original. I tried using a set of foreach loops that loops through every table in the dataset, every row in the table, and checking the RowState parameter, but they remain UnModified, because I don't call EndEdit() on the bindingsources (because I don't think I should do that until I'm actually saving). Obviously, I could handle the Changed event on each control that I bindto, and set a boolean to true anytime after binding, but that seems very overkill and it seems like there should be an easier/better/more efficent way.

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      There are AcceptChanges() function and EndEdit() function. DataSet changes are not commited until AcceptChanges is called, so I'm assuming you can call EndEdit and check the record state of your dataset for changes BEFORE saving the data. You shouldn't call AcceptChanges until you saved the data as it updates the state of your rows (added and edited rows become unchanged, deleted rows are removed) but you can call EndEdit anytime. "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia

      D 1 Reply Last reply
      0
      • E Edbert P

        There are AcceptChanges() function and EndEdit() function. DataSet changes are not commited until AcceptChanges is called, so I'm assuming you can call EndEdit and check the record state of your dataset for changes BEFORE saving the data. You shouldn't call AcceptChanges until you saved the data as it updates the state of your rows (added and edited rows become unchanged, deleted rows are removed) but you can call EndEdit anytime. "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia

        D Offline
        D Offline
        Drew McGhie
        wrote on last edited by
        #3

        Thanks, you helped me find my issue. All of my various usercontrols inhereted a definition for a .Save() method that would call endedit, but in one of them I set flags to mark a "last modified date" field, that was giving me false positives if I was just trying to check. EndEdit() was the end solution though. Thanks.

        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