2010-12-15 4 views
5

나는 값 I가 프로필 2 때 폼이로드를 선택하려는C# 목록 상자 세트 선택된 항목

Profile 1 
Profile 2 
Profile 3 

와 C# 1리스트 박스가있다. 어떻게해야합니까?

+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;

관련 문제