2011-09-23 4 views
0

콤보 박스가 표시 될 때 예를 들어 기본 국가를로드하려면 ("국가 : 레바논") 어떻게해야합니까? VS2008 (C#)을 사용하고 있습니다. 고맙습니다.콤보 박스의 기본로드

+1

윈폼? WebForms? WPF? 너 뭐 해봤 니? 코드를 게시 할 수 있습니까? – Oded

+0

@Oded Winforms이 경우. – Adrian

답변

0

일반적으로 양식이로드되면 바로 myCombo.SelectedValue = "Whatever value"을 설정합니다. ComboBox 제어

0

사용 SelectedValue 중 하나 SelectedIndex, SelectedItem 또는 SelectedText 속성.

0

이 작업을 시도 할 수 :

myCombo.SelectedIndex = lebanonsIndex; 
0

당신은 폼로드 이벤트에서 선택한 인덱스를 설정할 수 있습니다

레바논 comboboxItem selectedIndex = 0에 첫번째 경우

; 예 :

private void Form1_Load(object sender, EventArgs e) 
{ 
    comboBox1.SelectedIndex = 0; 
} 
0

당신은 Items 컬렉션

comboBox1.SelectedIndex = comboBox1.Items.IndexOf("Lebanon");// case sensitive 
0

이 일할 수에 같이 IndexOf를 사용하여 설정할 수 있습니다. 이 코드를 appsettings 내의 app.config 파일에 복사하십시오.

< add key="DefaultCountry" value="Lebanon" /> 

그리고 이것을보고 싶은 곳에서 복사하십시오.

combobox1.Text = System.Configuration.ConfigurationManager.AppSettings["DefaultCountry"].ToString();.<add key="DefaultCountry" value="Lebanon"/> 
1

일부 항목을 Combobox에 추가하면 ... 그냥 샘플 일뿐 아니라 항목을 추가하기 위해 루프를 실행할 수도 있습니다.

combobox1.Items.Add("USA"); 
combobox1.Items.Add("England"); 
combobox1.Items.Add("Kenya"); 
combobox1.Items.Add("South Africa"); 

이제 귀하의 콤보 박스에는 4 가지 항목이 있습니다. 선택하려면 특정 국가가 이것을 시도 :

combobox1.Text = "USA"; 

인덱스 기준에를 선택하려면 다음을 수행하십시오

combobox1.SelectedIndex = 0; // For USA 

그것이 도움이되기를 바랍니다.

1

당신은 콤보 상자 항목을 추가 할 다른 방법을 사용할 수 있습니다

comboBox1.Items.Insert(0, "Egypt"); 
//the first item is the item index and the second is the item object. 
관련 문제