大家好我已经使用DataGridViewComboBoxColumn绑定了我的datagridview,如下所示 dataGridView1.DataSource = db.DT(sql);
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的空值如下所示。我应该怎么做才能获得一个值 i tried this Why on Initial load DataGridViewComboBoxColumn showing empty value 但不起作用
答案 0 :(得分:0)
只需设置
Column1.DataPropertyName = "ID"
将解决问题