I have a C # list with values
Profile 1 Profile 2 Profile 3
I want to have Profile 2 selected when loading the form. How to do it?
Set the property ListBox.SelectedIndexto the Form.Shownevent.For instance:
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; }
Put the following code in the event Form.Loaded:
Form.Loaded
listBox1.SelectedItem = "Profile 2";
listBox1.Items.Add( " 1" );
listBox1.Items.Add( " 2" );
listBox1.Items.Add( " 3" );
listBox1.SelectedIndex = 1;