using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DataBindingFundamentalsSample { public partial class SimpleBindingAndItemDataSourcesForm : Form { RaceCarDriver raceCarDriver = new RaceCarDriver("M. Schumacher", 500); public SimpleBindingAndItemDataSourcesForm() { InitializeComponent(); //// Bind the Name and Wins properties to the name and wins text boxes //Binding nameBinding = new Binding("Text", raceCarDriver, "Name"); //this.nameTextBox.DataBindings.Add(nameBinding); //Binding winsBinding = new Binding("Text", raceCarDriver, "Wins"); //this.winsTextBox.DataBindings.Add(winsBinding); // Bind the Name and Wins properties to the name and wins text boxes this.nameTextBox.DataBindings.Add("Text", this.raceCarDriver, "Name", true); this.winsTextBox.DataBindings.Add("Text", this.raceCarDriver, "Wins", true); } private void addWinButton_Click(object sender, EventArgs e) { // Causes the RaceCarDriver object's WinsChanged event to fire, // which is used by the data binding infrastructure // to keep the text boxes up to date ++this.raceCarDriver.Wins; } } }