簡體   English   中英

將默認值添加到ComboBox

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM