I’m filling up a simple DataGridView (griVerifiche) with some values coming from my object vBuilder.
I can’t figure out why the values are not displayed in the grid (if I debug I can see that the rows have a value)
DataGridViewRowCollection tmpRowCollection = vBuilder.getDataGridFromExcel().Rows;
foreach(DataGridViewRow tmpRow in tmpRowCollection) {
DataGridViewRow rowClone = (DataGridViewRow)tmpRow.Clone();
griVerifiche.Rows.Add(rowClone);
int intColIndex = 0;
//Looping each column to fill the grid
foreach (DataGridViewCell cell in tmpRow.Cells)
{
griVerifiche.Rows[griVerifiche.Rows.Count - 1].Cells[intColIndex].Value = cell.Value;
intColIndex++;
}
}
griVerifiche.Refresh();
You should not refer to the last Row of the Grid because there is always an extra (last) row in the grid, used for adding new data.
Instead refer to the one before that (count-2).