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. WPF
  4. WPF data binding - How to cancel an edit

WPF data binding - How to cancel an edit

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpwcftutorial
6 Posts 2 Posters 19 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
    Simon P Stevens
    wrote on last edited by
    #1

    Hi, I have a WPF form for the user to edit some details of an object. Most of the fields are fairly simple text/numeric style fields. I've bound the controls to the properties on the object being edited, and everything works great. Except, how do I cancel the changes when the user hits the cancel button?

    Simon

    L 1 Reply Last reply
    0
    • S Simon P Stevens

      Hi, I have a WPF form for the user to edit some details of an object. Most of the fields are fairly simple text/numeric style fields. I've bound the controls to the properties on the object being edited, and everything works great. Except, how do I cancel the changes when the user hits the cancel button?

      Simon

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Simon, You have some options. 1. You can keep a copy of the object and replace the original values from the copy if the user cancels. 2. If this is a database application, just reread the record from the database. (or reread from the original source)

      Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

      Just a grain of sand on the worlds beaches.

      S 1 Reply Last reply
      0
      • L Lost User

        Simon, You have some options. 1. You can keep a copy of the object and replace the original values from the copy if the user cancels. 2. If this is a database application, just reread the record from the database. (or reread from the original source)

        Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

        Just a grain of sand on the worlds beaches.

        S Offline
        S Offline
        Simon P Stevens
        wrote on last edited by
        #3

        Thanks Karl, I was hoping there was something simpler than that. To be honest, it's easier to just go back to the old style and copy the object to the controls when the form is opened, then from the controls to the object when the user hits OK. I don't get the advantage of data binding. Am I missing something?

        Simon

        L 1 Reply Last reply
        0
        • S Simon P Stevens

          Thanks Karl, I was hoping there was something simpler than that. To be honest, it's easier to just go back to the old style and copy the object to the controls when the form is opened, then from the controls to the object when the user hits OK. I don't get the advantage of data binding. Am I missing something?

          Simon

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes I think you may be missing a number of built in features. WPF 3.5 now supports the IDataErrorInfo interface. There is plenty of info out there on WPF object data binding. I'm working on an article today that includes a notification control that is wired up to the business object. I about 2 weeks I'll also have a the 4th in my WPF Business Application series that covers "how to" do a great number of things with the data binding and business objects. Trust me, you want to try and use the WPF Data Binding. Very powerful. Bea Costa is the First Lady of WPF Data Binding. Here blog is here: http://www.beacosta.com/blog/[^]

          Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

          Just a grain of sand on the worlds beaches.

          S 1 Reply Last reply
          0
          • L Lost User

            Yes I think you may be missing a number of built in features. WPF 3.5 now supports the IDataErrorInfo interface. There is plenty of info out there on WPF object data binding. I'm working on an article today that includes a notification control that is wired up to the business object. I about 2 weeks I'll also have a the 4th in my WPF Business Application series that covers "how to" do a great number of things with the data binding and business objects. Trust me, you want to try and use the WPF Data Binding. Very powerful. Bea Costa is the First Lady of WPF Data Binding. Here blog is here: http://www.beacosta.com/blog/[^]

            Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

            Just a grain of sand on the worlds beaches.

            S Offline
            S Offline
            Simon P Stevens
            wrote on last edited by
            #5

            I'll stick with it. I'm still new to WPF, we're only using it in small internal apps at the moment. Nothing serious. I actually found something on her blog that helps with my original question http://www.beacosta.com/blog/?p=15[^]. If I set the update source trigger to explicit, and call UpdateSource() when the user hits OK, that looks like it will do what I want. I'll try it out. I'll keep a watch out for those articles, they sound useful. Thanks for the help,

            Simon

            L 1 Reply Last reply
            0
            • S Simon P Stevens

              I'll stick with it. I'm still new to WPF, we're only using it in small internal apps at the moment. Nothing serious. I actually found something on her blog that helps with my original question http://www.beacosta.com/blog/?p=15[^]. If I set the update source trigger to explicit, and call UpdateSource() when the user hits OK, that looks like it will do what I want. I'll try it out. I'll keep a watch out for those articles, they sound useful. Thanks for the help,

              Simon

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Simon, Glad to hear it. WPF has a learning curve, but it is worth it! :cool:

              Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

              Just a grain of sand on the worlds beaches.

              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