Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#列表框设置所选项目_C#_Winforms_Listbox_Listboxitem_Selected - Fatal编程技术网

C#列表框设置所选项目

C#列表框设置所选项目,c#,winforms,listbox,listboxitem,selected,C#,Winforms,Listbox,Listboxitem,Selected,我有一个带有值的C#列表框 Profile 1 Profile 2 Profile 3 我想在加载表单时选择配置文件2。如何执行此操作?在事件中设置属性。 例如: public Form1() { InitializeComponent(); // Adding the event handler in the constructor this.Shown += new EventHandler(Form1_Shown); } private void Fo

我有一个带有值的C#列表框

Profile 1
Profile 2
Profile 3
我想在加载表单时选择配置文件2。如何执行此操作?

在事件中设置属性。
例如:

public Form1()
{
    InitializeComponent();

    // Adding the event handler in the constructor
    this.Shown += new EventHandler(Form1_Shown);
}    

private void Form1_Shown(object sender, EventArgs e)
{
    myListBox.SelectedIndex = 1;
}

将以下代码放入
表单。已加载
事件:

listBox1.SelectedItem = "Profile 2";

你是说Winforms列表框?C本身可以与许多不同的UI框架一起使用。。。
listBox1.Items.Add("Profile 1");

listBox1.Items.Add("Profile 2");

listBox1.Items.Add("Profile 3");

listBox1.SelectedIndex = 1;