2013-03-24 2 views
0

나는 여러 콤보 상자에 SQL 데이터베이스 테이블 값이 채워진 Windows 양식 응용 프로그램이 있습니다. C# 편집시 콤보 상자에 값을 바인딩

하나의 코드의 예입니다

public void brandSelectCB(ComboBox cb) 
    { 
     string sSQL = " SELECT" + 
         "  id, name" + 
         " FROM" + 
         "  tbBrand" + 
         " ORDER BY" + 
         "  name"; 

     sqlConnect connect = new sqlConnect(); 
     DataTable dt = new DataTable(); 
     dt = connect.getBD(sSQL); 

     cb.DataSource = dt; 
     cb.DisplayMember = "name"; 
     cb.ValueMember = "id"; 

내 주요 양식과 같은 몇 가지 기록을 가지고 모델, 브랜드, 종류와 나는 특정 recor을 편집 할 때, 나는 레코드를 선택하고 클릭 이 같은 해당 텍스트 상자와 comboxes에 값을 입력 편집 버튼 :

private void btnEdit_Click(object sender, EventArgs e) 
    { 

      this.txtID.Text = lvMain.SelectedItems[0].SubItems[0].Text; 
      this.cbBrand.SelectedText = lvMain.SelectedItems[0].SubItems[1].Text; 
      this.cbModel.SelectedText = lvMain.SelectedItems[0].SubItems[2].Text; 
      this.txtName.Text = lvMain.SelectedItems[0].SubItems[3].Text; 
      this.cbType.SelectedText = lvMain.SelectedItems[0].SubItems[4].Text; 
    } 

잘 작동

, 내가 콤보 상자와 texboxes 텍스트를 얻을 수 있지만, 콤보 박스의 값은 만 선택되지 않은 텍스트가 있습니다. SelectedValue 또는 SelectedItem을 선택하면 아무 것도 얻을 수 없습니다. 내가 선택한 항목에서 해당 텍스트를 가지고 있지만 나는

내가 분명했다 콤보 :(에서 다시 한번 값을 선택해야합니다 : P

+0

항목을 직접 참조하고 선택한 값을 true로 설정하십시오. – SpykeBytes

+0

@SpykeBytes example plz – n3bi0s

답변

0

내가이 같은 작업을 가지고 :

int xcb; 
xcb = this.cbBrand.FindString(lvMain.SelectedItems[0].SubItems[1].Text); 
this.cbBrand.SelectedIndex = xcb; 
관련 문제