简体   繁体   中英

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.

        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 之类的位置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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