将默认值添加到ComboBox

Jam*_*son 1 c# .net-2.0

我有一个Windows应用程序正在使用ComboBox以前手工填写的"编辑项目".我正在改变它以从中获取数据Database table.

如何添加空值以便他们必须选择一个选项?

目前它会自动显示从我想知道的第一个人dataset,comboBox我想知道我如何强制它显示一个空白值作为默认值?

Designer生成的代码.

    // 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);
Run Code Online (Sandbox Code Playgroud)

kma*_*zek 8

Fill方法之后,您应该将SelectedItemproperty 设置为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;
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,用户必须从ComboBox中选择项目.