2010-12-15 164 views
5

我有值C#列表框组选择的项目

Profile 1 
Profile 2 
Profile 3 

我想有资料2选择的形式的负载时,C#列表框。我该怎么做呢?

+1

你的意思是一个Winforms列表框? C#本身可以用于许多不同的UI框架... – 2010-12-15 18:23:26

回答

17

Form.Shown事件中设置ListBox.SelectedIndex属性。
例如:在Form.Loaded事件

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; 
} 
+0

完美谢谢 – Ozzy 2010-12-15 18:36:43

7

穿戴以下代码:

listBox1.SelectedItem = "Profile 2"; 
0

listBox1.Items.Add( “资料1”);

listBox1.Items.Add(“Profile 2”);

listBox1.Items.Add(“Profile 3”);

listBox1.SelectedIndex = 1;