這是由C#生成設計類:如何將新項目添加到與實體綁定的組合框?
//
// usepurposeComboBox
//
this.usepurposeComboBox.DataSource = this.usepurposeBindingSource;
this.usepurposeComboBox.DisplayMember = "Name";
this.usepurposeComboBox.FormattingEnabled = true;
this.usepurposeComboBox.Location = new System.Drawing.Point(277, 53);
this.usepurposeComboBox.Name = "usepurposeComboBox";
this.usepurposeComboBox.Size = new System.Drawing.Size(218, 21);
this.usepurposeComboBox.TabIndex = 4;
this.usepurposeComboBox.ValueMember = "id";
//
// usepurposeBindingSource
//
this.usepurposeBindingSource.DataSource = typeof(mydatabaseEntities.usepurpose);
然後我綁定的BindingSource的(usepurposeBindingSource)到實體:
usepurposeBindingSource.DataSource = mydatabaseEntities.usepurposes;
而且因爲它被束縛我不能添加一個新行usepurposeComboBox。有沒有解決方法?
它不能這樣做。 System.Windows.Forms.dll中發生未處理的異常類型'System.ArgumentException' 其他信息:設置DataSource屬性時無法修改Items集合。 – JatSing
爲什麼不添加到'this.usepurposeBindingSource'? – balexandre