我有这个表单应用程序项目。我上传了销售领域的快照。有两个datagridview
。底部datagirdview
包含TAX details
. 包含底部datagrid
来自database except “Amount” column
。用户提供或自动计算的金额列值。我写一个代码。当我尝试执行时,它显示错误。Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index
. 我该如何解决?
折断::
这是代码:
private void dgvSalesFooterAdd_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)
{
decimal Total = 0;
decimal a=Convert.ToDecimal(lblTotalAdd.Text);
for (int i = 0; i <dgvSalesFooterAdd.Rows.Count ; i++)
{
dgvSalesFooterAdd.Rows[i].Cells[4].Value = a + (a * (Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[3].Value)/100));
Total += Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[4].Value);
}
lblFinalTotalAdd.Text = Total.ToString();
}
[注意:错误
dgvSalesFooterAdd.Rows[i].Cells[4].Value = a + (a * (Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[3].Value)/100));
Total += Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[4].Value);
这两条线。]