我有一个dataGridView,其中有许多列,所有列都由dataPropertyName绑定到dataSource。
datagridviewcombobox应该显示项目列表(这些项目具有多个属性,一个ID属性和一个Name属性,这些属性也存储在数据网格的数据源中。
根据我为每个datagridviewbombobox单元格设置的值,我希望显示属性的匹配名称。
一切正常,所有datagridviewcomboboxcells中的值都是正确的,我设置了display和value成员。那么为什么datagridviewcombobox不显示任何内容?
我查看了发现的大多数线程,但找不到解决方法。
预先感谢您的帮助。
List<ProcessGroup> processGroups = _context.ProcessGroup.ToList();
_ds = new List<TestRessourceDetailsModel>();
for (int i = 0; i < processGroups.Count; i++)
{
List<IntrusionBody> ibs = null;
int? id = _curTestRes.TestResourceProcessGroup.OrderBy(x => x.ProcessGroupID).Where(y => y.ProcessGroupID == i + 1).FirstOrDefault()?.ID;
if (_view.Cb_Location.SelectedItem != null)
{
if (_curTestRes != null)
{
ibs = _context.IntrusionBody.Where(x => x.ProcessGroupID == i + 1 && x.ToDate == null && (x.TestRessourceProcessGroupID == null || x.TestRessourceProcessGroupID == id)).ToList();
}
else
{
ibs = _context.IntrusionBody.Where(x => x.ProcessGroupID == i + 1 && ((Location)_view.Cb_Location.SelectedItem).ID == x.LocationID && x.ToDate == null && x.TestRessourceProcessGroupID == null).ToList();
}
}
else
{
ibs = _context.IntrusionBody.Where(x => x.ProcessGroupID == i + 1 && x.ToDate == null && x.TestRessourceProcessGroupID == null || x.TestRessourceProcessGroupID == id).ToList();
}
_ds.Add(new TestRessourceDetailsModel
{
ProcessGroup = processGroups[i].Name,
E_DIN = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "E (DIN)").FirstOrDefault()?.Activated,
E_U_DIN = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "E+U (DIN)").FirstOrDefault()?.Activated,
R_DIN = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "R (DIN)").FirstOrDefault()?.Activated,
E_REF_DIN = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "E (Ref. DIN)").FirstOrDefault()?.Activated,
E_ASTM = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "E (ASTM)").FirstOrDefault()?.Activated,
E_U_ASTM = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "E+U (ASTM)").FirstOrDefault()?.Activated,
R_ASTM = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "R (ASTM)").FirstOrDefault()?.Activated,
E_REF_ASTM = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestOptionTestRessourceProcessGroup.Where(x => x.TestOption.Name == "E (Ref. ASTM)").FirstOrDefault()?.Activated,
NrOfImpressions = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.NrOfImpressions,
TestsPerDay = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.NrOfTestPerDay,
IntrusionBody = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.IntrusionBody.Where(x => x.ToDate == null).FirstOrDefault(),
IntrusionBodies = ibs,
DINLocked = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.DINLocked,
ASTMLocked = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.ASTMLocked,
Active = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.Active,
IsCertifiedDin = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestResourceProcessGroupCertification.Where(x => x.Date.Year == DateTime.Now.Year).FirstOrDefault()?.DIN,
IsCertifiedAstm = processGroups[i].TestResourceProcessGroup.Where(x => x.TestResourceID == _curTestRes?.ID).FirstOrDefault()?.TestResourceProcessGroupCertification.Where(x => x.Date.Year == DateTime.Now.Year).FirstOrDefault()?.ASTM
});
}
_view.Dgv_ProcessGroups.AutoGenerateColumns = false;
_view.Dgv_ProcessGroups.DataSource = _ds;
((DataGridViewCheckBoxColumn)_view.Dgv_ProcessGroups.Columns[13]).ThreeState = true;
((DataGridViewCheckBoxColumn)_view.Dgv_ProcessGroups.Columns[14]).ThreeState = true;
foreach (DataGridViewRow row in _view.Dgv_ProcessGroups.Rows)
{
((TestRessourceDetailsModel)row.DataBoundItem).IntrusionBodies.Insert(0, new IntrusionBody { ID = 999999, Name = "" });
((DataGridViewComboBoxCell)row.Cells[12]).DataSource = ((TestRessourceDetailsModel)row.DataBoundItem).IntrusionBodies;
((DataGridViewComboBoxCell)row.Cells[12]).DisplayMember = "Name";
((DataGridViewComboBoxCell)row.Cells[12]).ValueMember = "ID";
if (((TestRessourceDetailsModel)row.DataBoundItem).IntrusionBody != null)
{
((DataGridViewComboBoxCell)row.Cells[12]).Value = ((TestRessourceDetailsModel)row.DataBoundItem).IntrusionBody?.ID;
}
else if (((TestRessourceDetailsModel)row.DataBoundItem).IntrusionBodies.Count > 0)
{
((DataGridViewComboBoxCell)row.Cells[12]).Value = ((TestRessourceDetailsModel)row.DataBoundItem).IntrusionBodies.First().ID;
}
}