2012-07-01 2 views
1

내 Windows Form에는 Categories bindingsource에 바인딩 된 1 개의 콤보 박스와 Products 바인딩 소스에 바인딩 된 1 개의 DataGrid가 들어 있습니다. 양식을로드 할 때 콤보 상자는 Products 테이블에서 선택한 값이 아닌 categories 테이블의 첫 번째 값을 표시하고 제품 바인딩 소스에서 위치를 변경할 때 combobox에서 올바른 값을 얻을 수 있습니다 (올바른 값을 표시 함). 그래서 내 문제는 콤보 상자 항목의 첫 번째로드에 있습니다.Winform Combobox - 양식로드시 올바르지 않은 선택 값

내 콤보 속성 :

데이터 소스 = categorybindingsource

디스플레이 회원 = 범주가

값 회원 = 카테고리 ID

이 값은 = productBindingSource 선택한 것이 - 여기 카테고리 ID

그리고는 내 코드 :

NorthwindDataContext dc; 
private void Form1_Load(object sender, EventArgs e) 
{ 
    dc = new NorthwindDataContext(); 
    productBindingSource.DataSource = dc.Products; 

    this.categoryIDComboBox.DataSource = dc.Categories; 
} 

답변

1

시도 맞아 콤보 및 데이터 그리드

NorthwindDataContext dc; 
private void Form1_Load(object sender, EventArgs e) 
{ 
    dc = new NorthwindDataContext(); 
    this.categoryIDComboBox.DataSource = dc.Categories; 
    productBindingSource.DataSource = dc.Products; 
} 
+0

의 초기화의 순서를 반전, 콤보의 초기화 데이터 그리드 전에해야합니다, 당신에게 스티브 감사합니다. –