How do I bind a field to a control in WinForms?
Assume there is a class Person {Name} and we want to bind the name of the person to a textbox.text property. How is this accomplished?
something similar to:
nameTextbox.DataBindings.Add(...)
I have done this in WPF using DepedencyProperties but haven't find any开发者_JAVA技巧thing similar to WinForms
This is amazingly simple. Seems to be working out of the box. I must bee blind for not figuring this earlier
Person person1 = new Person();
person1.Name = "Odys";
textbox.DataBindings.Add("Text", person1, "Name");
Works just fine!
You need to create a BindingSource and use the Person instance as DataSource for this. Then you have to bind the TextBox Text Property to the BindingSource.
精彩评论