値が記載されたC#リストボックスがあります
Profile 1
Profile 2
Profile 3
フォームの読み込み時にプロファイル2を選択したい。どうすればよいですか?
値が記載されたC#リストボックスがあります
Profile 1
Profile 2
Profile 3
フォームの読み込み時にプロファイル2を選択したい。どうすればよいですか?
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;
}
イベントに次のコードを入れますForm.Loaded
:
listBox1.SelectedItem = "Profile 2";
listBox1.Items.Add("Profile 1");
listBox1.Items.Add("Profile 2");
listBox1.Items.Add("Profile 3");
listBox1.SelectedIndex = 1;