[英]Adding default value to ComboBox
我有一個Windows應用程序,該應用程序使用的ComboBox
以前是手工填寫的“編輯項”。 我正在更改它以從Database table
獲取數據。
如何添加空白值,以便他們必須選擇一個選項?
目前,它會自動顯示從comboBox
dataset
返回的第一個人,我想知道如何強制其顯示空白值作為默認值?
設計器生成的代碼。
// attorneySelectDropDown
//
this.attorneySelectDropDown.DataSource = this.jMeFileAssignAttorneyBindingSource;
this.attorneySelectDropDown.DisplayMember = "name";
this.attorneySelectDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.attorneySelectDropDown.FormattingEnabled = true;
this.attorneySelectDropDown.Location = new System.Drawing.Point(13, 15);
this.attorneySelectDropDown.Name = "attorneySelectDropDown";
this.attorneySelectDropDown.Size = new System.Drawing.Size(298, 21);
this.attorneySelectDropDown.TabIndex = 4;
this.attorneySelectDropDown.ValueMember = "name";
this.attorneySelectDropDown.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
在Fill
方法之后,應將SelectedItem
屬性設置為null:
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'stackoverflowDataSet.Person' table. You can move, or remove it, as needed.
this.personTableAdapter.Fill(this.stackoverflowDataSet.Person);
comboBox1.SelectedItem = null;
}
在這種情況下,用戶必須從ComboBox中選擇項目。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.