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