2010-12-15 22 views
5

私は値C#のリストボックスセット選択項目

Profile 1 
Profile 2 
Profile 3 

とC#のリストボックスを持っている私は、プロファイルフォームのロード選択した2を持っていると思います。これはどうすればいいですか?

+1

Winformsリストボックスを意味しますか? C#自体は、さまざまなUIフレームワークで使用することができます... –

答えて

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

7

プット以下のコード:例えば

listBox1.SelectedItem = "Profile 2"; 
0

listBox1.Items.Add( "プロファイル1")。

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

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

listBox1.SelectedIndex = 1;