Winfrom DataGridView DataGridViewComboBoxCell 数据源绑定
解决方案:
1.先给数据源赋值
List<BindDataModel> ProcessStatus = new List<BindDataModel>
{
new BindDataModel() { _name = "生产中", _value = "生产中" },
new BindDataModel() { _name = "暂停", _value = "暂停" },
};
2.绑定数据源
private void showData()
{
if (pOSchListEntities.Count > 0)
{
for (int i = 0; i < dgvPOlist.Rows.Count; i++)
{
((DataGridViewComboBoxCell)dgvPOlist.Rows[i].Cells["WoSchStatus"]).DataSource = ProcessStatus;
((DataGridViewComboBoxCell)dgvPOlist.Rows[i].Cells["WoSchStatus"]).DisplayMember = "_name";
((DataGridViewComboBoxCell)dgvPOlist.Rows[i].Cells["WoSchStatus"]).ValueMember = "_value";
var _MfgOrder = dgvPOlist.Rows[i].Cells["MfgOrderName"].Value?.ToString();
var _MfgLine = dgvPOlist.Rows[i].Cells["MfgLineName"].Value?.ToString();
var _ProcessData = pOSchListEntities.Where(t => t.MfgLineName == _MfgLine && t.MfgOrderName == _MfgOrder).ToList().FirstOrDefault().InProcesss;
((DataGridViewComboBoxCell)dgvPOlist.Rows[i].Cells["WoSchStatus"]).Value = _ProcessData;
}
}
}
|