2016-10-15 50 views
0

大家好我已經用DataGridViewComboBoxColumn綁定了我的datagridview,如下所示 dataGridView1.DataSource = db.DT(sql);如何加載特定的值DataGridViewComboBoxColumn

 DataGridViewComboBoxColumn Column1 = new DataGridViewComboBoxColumn(); 
     Column1.HeaderText = "Status"; 

     Column1.Name = "Column1"; 
     DTchequeStatus = db.DT("SELECT [ID] ,[Status] FROM [ChequeStatus]"); 

     Column1.DisplayMember = "Status"; 
     Column1.ValueMember = "ID"; 
     Column1.DataSource = DTchequeStatus; 



     foreach (DataRow DR in DTchequeStatus.Rows) 
     { 

      // Column1.Items.Add(DR["Status"].ToString()); 
     } 
     this.dataGridView1.Columns.Add(Column1); 



     dataGridView1.Columns["Column1"].ReadOnly = false; 
     foreach (DataGridViewRow DR in dataGridView1.Rows) 
     { 
      (DR.Cells["Column1"] as DataGridViewComboBoxCell).Value = (int)DR.Cells["Cheque Status"].Value; 
     } 

但是這導致我的datagridview的一個空值如下。我應該怎麼做序,以獲得一個價值選擇的enter image description herei tried this Why on Initial load DataGridViewComboBoxColumn showing empty value但不工作

+0

你忘了設置'Column1.DataPropertyName =「SomeField」 '。 –

+0

@RezaAghaei'Column1.DataPropertyName =「狀態」;'設置但不起作用 –

+1

不工作不是一個合適的問題描述。設置Column1.DataPropertyName =「Status」後發生了什麼事? 'Status'列是否屬於DataGridView的'DataSource'表? –

回答

0

只設置

Column1.DataPropertyName = "ID" 

意願解決問題

相關問題