C#设置下拉列表默认值

问题描述 投票:-1回答:1

我正在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;

enter image description here

您知道我该如何解决吗?预先感谢。

c# list dropdown
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.