6

値が記載されたC#リストボックスがあります

Profile 1
Profile 2
Profile 3

フォームの読み込み時にプロファイル2を選択したい。どうすればよいですか?

4

3 に答える 3

22

ListBox.SelectedIndexイベントでプロパティを設定しますForm.Shown
例えば:

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;
}
于 2010-12-15T18:22:33.197 に答える
6

イベントに次のコードを入れますForm.Loaded

listBox1.SelectedItem = "Profile 2";
于 2010-12-15T18:22:53.610 に答える
0
listBox1.Items.Add("Profile 1");

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

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

listBox1.SelectedIndex = 1;
于 2010-12-15T18:51:27.057 に答える