我有一個WinForm應用程序,每個行都包含一個包含ComboBox的網格。所有都綁定到相同的集合(集合可能會改變,這就是爲什麼我不想爲每個組合都有不同的集合,也是內存成本)。問題是,當我在一個組合中選擇一個對象時,它將更改每個組合中的選定對象。 這是一個您可以運行並輕鬆再現的代碼。.Net上的錯誤行爲控件數據源屬性
public Form1()
{
InitializeComponent();
this.comboBox1 = new System.Windows.Forms.ComboBox();
List<int> numList = new List<int>(){1,2,3,4};
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(33, 169);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(126, 21);
this.comboBox1.TabIndex = 3;
this.comboBox1.DataSource = numList; // BINDING TO NUMLIST
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(243, 367);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(126, 21);
this.comboBox2.TabIndex = 4;
this.comboBox2.DataSource = numList; // BINDING TO NUMLIST (THE SAME LIST
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.comboBox1);
}
只是做一個表格並粘貼組合框1和2 任何想法這可怎麼發生的聲明。我的意思是如果它是一個簡單的列表,它不會跟蹤選定的對象。 DataSource背後發生了什麼?
我真的很討厭她,那是指行爲小姐! – leppie 2009-10-29 16:07:35
我其實讀過這個問題,因爲我有興趣去見她。 – Paddy 2009-10-29 16:52:37