9using System.Collections.Generic;
10using System.ComponentModel;
13using System.Windows.Forms;
19 public partial class Form1 : Form
21 private ListBox listBox1;
22 private Button button1;
23 private TextBox textBox1;
27 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
28 this.textBox1 =
new System.Windows.Forms.TextBox();
29 this.listBox1 =
new System.Windows.Forms.ListBox();
30 this.button1 =
new System.Windows.Forms.Button();
31 this.textBox1.Location =
new System.Drawing.Point(169, 26);
32 this.textBox1.Size =
new System.Drawing.Size(100, 20);
33 this.textBox1.Text =
"new element";
34 this.listBox1.FormattingEnabled =
true;
35 this.listBox1.Location =
new System.Drawing.Point(12, 12);
36 this.listBox1.Size =
new System.Drawing.Size(120, 95);
37 this.button1.Location =
new System.Drawing.Point(180, 83);
38 this.button1.Size =
new System.Drawing.Size(95, 23);
39 this.button1.Text =
"Add New Object";
40 this.button1.Click +=
new System.EventHandler(this.button1_Click);
41 this.ClientSize =
new System.Drawing.Size(292, 266);
42 this.Controls.Add(this.button1);
43 this.Controls.Add(this.listBox1);
44 this.Controls.Add(this.textBox1);
45 this.Text =
"Databinding Tests";
46 this.Load +=
new EventHandler(Form1_Load);
60 set { _name = value; }
76 void Form1_Load(
object sender, EventArgs e)
85 dataSource.RaiseListChangedEvents =
true;
86 dataSource.AllowNew =
true;
87 dataSource.AllowRemove =
false;
88 dataSource.AllowEdit =
false;
90 listBox1.DataSource = dataSource;
91 listBox1.DisplayMember =
"Data";
93 dataSource.ListChanged +=
new ListChangedEventHandler(dataSource_ListChanged);
101 MessageBox.Show(
"AddingNew event raised");
105 private void button1_Click(
object sender, EventArgs e)
110 if (newObject.Data.Contains(
" "))
112 MessageBox.Show(
"CancelNew: data property cannot contain spaces");
113 MessageBox.Show(
"CancelNew: index is " + dataSource.IndexOf(newObject).ToString());
115 dataSource.CancelNew(dataSource.IndexOf(newObject));
116 Console.WriteLine(dataSource.IndexOf(newObject));
121 dataSource.EndNew(dataSource.IndexOf(newObject));
135 void dataSource_ListChanged(
object sender, ListChangedEventArgs e)
137 MessageBox.Show(
"ListChanged event raised: " + e.ListChangedType.ToString());
149 Application.EnableVisualStyles();
151 Application.Run(newForm1);
154 private void InitializeComponent()
156 this.SuspendLayout();
160 this.ClientSize =
new System.Drawing.Size(292, 266);
161 this.Name =
"Databinding tests";
162 this.Load +=
new System.EventHandler(this.Form1_Load);
163 this.ResumeLayout(
false);
static ListObject GetList()