简体   繁体   English

C# 设置下拉列表默认值

[英]C# Set dropdown list default value

I'm setting default value of dropdown list in Form.Designer.cs, but when I change position of this or even another object in the design window, this line disappears and dropdown list doesn't display any value.我在 Form.Designer.cs 中设置下拉列表的默认值,但是当我在设计窗口中更改此对象或什至另一个对象的位置时,此行消失并且下拉列表不显示任何值。

        this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.comboBox2.Enabled = true;
        this.comboBox2.FormattingEnabled = true;
        this.comboBox2.Items.AddRange(new object[] {
        "beam center",
        "force application"});
        this.comboBox2.Location = new System.Drawing.Point(402, 258);
        this.comboBox2.Name = "comboBox2";
        this.comboBox2.Size = new System.Drawing.Size(121, 21);
        this.comboBox2.TabIndex = 45;
        this.comboBox2.SelectedIndex = 0;

在此处输入图片说明

Do you know how could I fix that?你知道我怎么能解决这个问题吗? Thanks in advance.提前致谢。

将其从设计器生成的代码中移出并移至 Form_Load 之类的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM