I asked this same question last week and ended up getting a solution to my problem thanks to user @Aaron . However, I'm asking again because the code works perfectly in one project but doesn't work in another project under almost the exact same conditions (ie. # of columns/rows, type of variable, how the DGV is populated).
//This is my code to go through each cell in the DataGridView.
for (int i = 0; i < dgvTest.RowCount; i++)
{
for (int j = 0; j < dgvTest.ColumnCount; j++)
{
foreach (Information info in frmMain._dbList)
{
if (dgvTest.Rows[i].Cells[j].Value.ToString().ToLower() == info.InfoName.ToLower() && info.InfoInputType == "1")
{
DataGridViewComboBoxCell c = new DataGridViewComboBoxCell();
c.Items.Add("0");
c.Items.Add("1");
dgvTest.Rows[i].Cells[(j + 1)] = c;
}
}
}
}
PROBLEM:
Once I click "OK" oddly enough, it creates the ComboBox. If I repeat this process, it will eventually populate each cell with the ComboBox, but whenever I mouse over them the same error message pops up.
Is it setting the cell to the combobox and then trying to go back over the same cell?
SOLVED
Simple solution - had to add a c.Value = # to set the value.