C#列表框设置所选项目
我有一个带有值的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
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;