2010-12-15 24 views
5

i değerlere Ben Profil 2 zaman formu yükleri seçilmiş olmasını istiyorumC# liste kutusu seti Seçilen öğe

Profile 1 
Profile 2 
Profile 3 

ile C# liste vardır. Bunu nasıl yaparım?

+1

Winforms liste kutusunu mı kastediyorsunuz? C# kendisi birçok farklı UI çerçeveleri ile kullanılabilir ... –

cevap

17

Form.Shown etkinliğinde ListBox.SelectedIndex özelliğini ayarlayın. Form.Loaded olay

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

mükemmel çalıştı teşekkürler – Ozzy

7

koyun aşağıdaki kodu: Örneğin

listBox1.SelectedItem = "Profile 2"; 
0

ListBox1.Items.Add ("Profil 1");

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

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

listBox1.SelectedIndex = 1;