2013-05-27 3 views
1

의 선택된 항목의 값/이름을 검색, 나는 데이터베이스에서 바인딩 콤보를 가지고, 각 항목은 이름과 값을 콤보 상자의 선택 항목의 값을 검색 할 :나는 윈폼 응용 프로그램에서 일하고 있어요으로 comboBox

string curentIdTem = comboBox2.SelectedValue.ToString(); 

comboBox2.SelectedValue의 반환 값은 누군가가 제발 도움이 될 수 있습니다, 'NULL'항상?

+1

'SelectedValue'가'int'인지 확인할 수 있습니까 –

+0

@jacobalucious 그것은 '문자열'입니다. –

+0

참조 http://stackoverflow.com/questions/6901070/getting-selected-value-of-a-combobox – Adil

답변

1

이 시도 :

int curentIdTem = Convert.ToInt32(((themeS)comboBox2.SelectedItem).Value); 
1

themeS을 사용하여 작동하지 않는 int으로 전송 중입니다.

Value 속성의 int 값이 themeS 클래스 인 것으로 예상되는 경우 Int32.TryParse

int currentItem = 0; 
    Int32.TryParse(((themeS)comboBox2.SelectedValue).Value, out  currentItem); 
1

을 당신이 ComboBox

예에 ValueMember를 설정해야 SelectedValue를 사용하려면

그런 다음 당신은이 방법을 검색 할 수 있습니다 :

comboBox1.ValueMember = "Value"; 
    ..... 

    int value = (int)comboBox2.SelectedValue; 
관련 문제