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. Simple .Net 2.0 Data Binding question (WinForms)

Simple .Net 2.0 Data Binding question (WinForms)

Scheduled Pinned Locked Moved C#
csharpwinformsquestionwpfwcf
5 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.
  • F Offline
    F Offline
    Furty
    wrote on last edited by
    #1

    I'm wrestling with the new Windows Forms data binding in .Net 2.0 without much luck. Here's my data binding source object: public class UserCredentials { #region Fields private string userName; private string password; #endregion #region Properties /// /// Gets or Sets the user name /// public string UserName { get { return userName; } set { userName = value; } } /// /// Gets or Sets the password /// public string Password { get { return password; } set { password = value; } } #endregion } I then create a simple Form with TextBoxes for the user name and password, and bind the Text property to the relevant properties in my binding source. I also have some simple validation code to check that data has been entered, and have provided a Cancel button on the Form so the user can back out of any changes made. In the form's constructor I set the DataSource property of the BindingSource to an instance of the UserCredentials class. So far so good, the UserName and Password properties of the UserCredentials class are binding to my two TextBoxes just fine. The problem is, I can't find any way to roll-back the changes made to my UserCredentials instance if validation fails, or the user clicks Cancel. I'm sure it's very simple, but I just can't see it right now.. Any ideas?

    I B 2 Replies Last reply
    0
    • F Furty

      I'm wrestling with the new Windows Forms data binding in .Net 2.0 without much luck. Here's my data binding source object: public class UserCredentials { #region Fields private string userName; private string password; #endregion #region Properties /// /// Gets or Sets the user name /// public string UserName { get { return userName; } set { userName = value; } } /// /// Gets or Sets the password /// public string Password { get { return password; } set { password = value; } } #endregion } I then create a simple Form with TextBoxes for the user name and password, and bind the Text property to the relevant properties in my binding source. I also have some simple validation code to check that data has been entered, and have provided a Cancel button on the Form so the user can back out of any changes made. In the form's constructor I set the DataSource property of the BindingSource to an instance of the UserCredentials class. So far so good, the UserName and Password properties of the UserCredentials class are binding to my two TextBoxes just fine. The problem is, I can't find any way to roll-back the changes made to my UserCredentials instance if validation fails, or the user clicks Cancel. I'm sure it's very simple, but I just can't see it right now.. Any ideas?

      I Offline
      I Offline
      Ista
      wrote on last edited by
      #2

      use a BindingManagerBase object to send the values back to the data source unfortunately, its only set up for a dataViewRow objects. But if you extend the BindingManagerBase and a few other classes you can get there I believe the class you need to get to is ContextManager which has the refresh method to create your own deriving it from BinidingManagerBase. Its been a year since I did that. But, it rocks when your done. Nick I'm not an expert yet, but I play one at work. Yeah and here too.

      F 1 Reply Last reply
      0
      • I Ista

        use a BindingManagerBase object to send the values back to the data source unfortunately, its only set up for a dataViewRow objects. But if you extend the BindingManagerBase and a few other classes you can get there I believe the class you need to get to is ContextManager which has the refresh method to create your own deriving it from BinidingManagerBase. Its been a year since I did that. But, it rocks when your done. Nick I'm not an expert yet, but I play one at work. Yeah and here too.

        F Offline
        F Offline
        Furty
        wrote on last edited by
        #3

        Hrmm, are you sure you're talking about .Net 2.0 object data binding? It would be much easier just to Set/Get the Text properties of a couple of TextBox controls than go to that level of work. I was really hoping the data binding in .Net 2.0 was an improvemnt over the 1.0 stuff :(

        1 Reply Last reply
        0
        • F Furty

          I'm wrestling with the new Windows Forms data binding in .Net 2.0 without much luck. Here's my data binding source object: public class UserCredentials { #region Fields private string userName; private string password; #endregion #region Properties /// /// Gets or Sets the user name /// public string UserName { get { return userName; } set { userName = value; } } /// /// Gets or Sets the password /// public string Password { get { return password; } set { password = value; } } #endregion } I then create a simple Form with TextBoxes for the user name and password, and bind the Text property to the relevant properties in my binding source. I also have some simple validation code to check that data has been entered, and have provided a Cancel button on the Form so the user can back out of any changes made. In the form's constructor I set the DataSource property of the BindingSource to an instance of the UserCredentials class. So far so good, the UserName and Password properties of the UserCredentials class are binding to my two TextBoxes just fine. The problem is, I can't find any way to roll-back the changes made to my UserCredentials instance if validation fails, or the user clicks Cancel. I'm sure it's very simple, but I just can't see it right now.. Any ideas?

          B Offline
          B Offline
          bismark
          wrote on last edited by
          #4

          You need to implement IEditableObjectinterface. And write code to BeginEdit, EndEdit and CancelEdit You can check CSLA Framework on Internet to check how implement IEditableObject interface Regards

          F 1 Reply Last reply
          0
          • B bismark

            You need to implement IEditableObjectinterface. And write code to BeginEdit, EndEdit and CancelEdit You can check CSLA Framework on Internet to check how implement IEditableObject interface Regards

            F Offline
            F Offline
            Furty
            wrote on last edited by
            #5

            Thanks bismark, that of course worked. After seeing all the improvements to data binding during design time, I had hoped the powers that be had built a better mousetrap for object binding in V2.0, but not so hey.

            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