Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Data Binding

using System; using System.Drawing; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Windows.Forms; public class DataBoundStringCollection : System.Windows.Forms.Form {   private Button RightButton= new Button();   private Button LeftButton= new Button();   private TextBox textBox2 = new TextBox();   private TextBox textBox1 = new TextBox();   private Button DoneButton= new Button();   private StringCollection sa=new StringCollection();     public DataBoundStringCollection()     {     this.textBox2.Location = new Point(184, 16);     this.RightButton.Location = new Point(192, 64);     this.RightButton.Text = ">>";     this.RightButton.Click += new EventHandler(this.RightButton_Click);     this.textBox1.Location = new Point(8, 16);     this.DoneButton.Location = new Point(104, 64);     this.DoneButton.Text = "Done";     this.DoneButton.Click += new EventHandler(this.DoneButton_Click);     this.LeftButton.Location = new Point(16, 64);     this.LeftButton.Text = "<<";     this.LeftButton.Click += new EventHandler(this.LeftButton_Click);     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);     this.ClientSize = new System.Drawing.Size(294, 111);     this.ControlBox = false;     this.Controls.AddRange(new Control[] {                   this.RightButton,                   this.LeftButton,                   this.textBox2,                   this.textBox1,                   this.DoneButton});     this.FormBorderStyle = FormBorderStyle.FixedDialog;     this.ShowInTaskbar = false;     this.ResumeLayout(false);     sa.Add("A");     sa.Add("B");     sa.Add("C");     sa.Add("D");     this.textBox1.DataBindings.Add("Text",sa,"");     this.textBox2.DataBindings.Add("Text",sa,"");     }     public override void Dispose()     {         base.Dispose();     }   protected void RightButton_Click (object sender, System.EventArgs e)   {     this.BindingContext[sa].Position++;   }   protected void LeftButton_Click (object sender, System.EventArgs e)   {     this.BindingContext[sa].Position--;   }   protected void DoneButton_Click (object sender, System.EventArgs e)   {     Application.Exit();   }   public static void Main()   {     Application.Run(new DataBoundStringCollection());   } }