【发布时间】:2013-04-09 17:50:26
【问题描述】:
是否可以使用以下内容向绑定源添加一行:
"Please Select..." <-- what it will display on the combobox
DbNull.Value <-- Value
我有一个组合框,它是绑定到绑定源的数据。我不想向数据库添加额外的行,而是有一个选项只显示在组合框中,因此当它读取上述内容时,它会在数据库中设置相应的值。另外因为还有其他组合框使用相同的数据成员和数据源,所以我只想将选项添加到那个特定的组合框。
以上是设计器文件 InitializeComponent() 方法的内容
this.cmbSecCSR = new System.Windows.Forms.ComboBox();
this.csrBindingSource2 = new System.Windows.Forms.BindingSource(this.components);
this.cmbSecCSR.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.cmbSecCSR.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
// this.cmbSecCSR.Items.Insert(0, "Select");
this.cmbSecCSR.DataSource = this.csrBindingSource2;
this.cmbSecCSR.DisplayMember = "Name";
this.cmbSecCSR.FormattingEnabled = true;
this.cmbSecCSR.Location = new System.Drawing.Point(112, 26);
this.cmbSecCSR.Margin = new System.Windows.Forms.Padding(0);
this.cmbSecCSR.Name = "cmbSecCSR";
this.cmbSecCSR.Size = new System.Drawing.Size(184, 21);
this.cmbSecCSR.TabIndex = 2;
this.cmbSecCSR.ValueMember = "Username";
this.cmbSecCSR.TextChanged += new System.EventHandler(this.comboBox_TextChanged);
this.cmbSecCSR.Enter += new System.EventHandler(this.cmbBox_Entered);
// csrBindingSource2
//
this.csrBindingSource2.DataMember = "CSR";
this.csrBindingSource2.DataSource = this.productionDS;
//
【问题讨论】:
-
只需定义另一个源,该源仅引用另一个源并将该行插入位置 0。
-
这个的初始化是在Designer.CS中完成的......应该在那里完成......??
-
在您展示 CompboBox 所绑定的内容之前,无法提供具体信息。
-
“组合框绑定到什么”?什么是 csrBindingSource2 以及它是如何填充的。
-
CsrBindingSource 引用了一个 Datasheet ProductionDS,其中有一个名为 CSR 的数据表
标签: c# .net winforms data-binding