У меня есть dataGridView с множеством столбцов, все связаны с источником данных с помощью dataPropertyName.
В datagridviewcombobox должен отображаться список элементов (эти элементы имеют несколько свойств, одно свойство ID и одно свойство Name, которое также хранится в источнике данных сетки данных.
В соответствии сзначение, которое я устанавливаю для каждой ячейки datagridviewbomboboxcell, я хочу, чтобы отображалось соответствующее имя свойства.
Все работает, значение во всех datagridviewcombobcecells верно, я устанавливаю элемент 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;
}
}