索引超出了数组界限,急!!!!!
int num=0;
foreach (DataGridViewRow dgvRow in dgvCharge.Rows)
{
if (dgvRow.Cells["dgvcbc"] != null && dgvRow.Cells["dgvcbc"].Value != null)
if (dgvRow.Cells["dgvcbc"].Value.Equals(true))
{
------------------------下一行报错
PayInfo.ComputeChargeRecordID[num] = Convert.ToInt32(dgvRow.Cells["colChargeID"].Value);
decimal remainMoney = Convert.ToDecimal(dgvRow.Cells["colRemainMoney"].Value);
decimal remainWater = Convert.ToDecimal(dgvRow.Cells["colRemainWater"].Value);
DataSet ds = bll.GetChargeDetailInfo(PayInfo.ComputeChargeRecordID[num]);
decimal recMoney = 0;
decimal factMoney = 0;
decimal recLateFee = 0;
decimal discountMoney = 0;
decimal cutLateFee = 0;
decimal factualLateFee = 0;
PayInfo.FactualMoney[num] = Convert.ToDouble(factMoney);
PayInfo.PayWaterMuch[num] = Convert.ToDouble(remainWater * factMoney / remainMoney);
PayInfo.ReceivableMoney[num] = PayInfo.FactualMoney[num];
PayInfo.ReceivableWater[num] = PayInfo.PayWaterMuch[num];
PayInfo.ReceivableLateFee[num] = Convert.ToDouble(recLateFee);
PayInfo.ChargeDiscount[num] = Convert.ToDouble(discountMoney);
PayInfo.LateFeeDiscount[num] = Convert.ToDouble(cutLateFee);
PayInfo.FactualLateFee[num] = Convert.ToDouble(factualLateFee);
PayInfo.PlanInWater[num] = Convert.ToDouble(dgvRow.Cells["PlanInWater"].Value.ToString());
PayInfo.PlanInMoney[num] = Convert.ToDouble(dgvRow.Cells["PlanInMoney"].Value.ToString());
PayInfo.PlanOutWater[num] = Convert.ToDouble(dgvRow.Cells["PlanOutWater"].Value.ToString());
PayInfo.PlanOutMoney[num] = Convert.ToDouble(dgvRow.Cells["PlanOutMoney"].Value.ToString());
num++;
}
}
}
为什么???
------解决方案--------------------if (dgvRow.Cells["dgvcbc"] != null && dgvRow.Cells["dgvcbc"].Value != null)
------------>
if (dgvRow.Cells["dgvcbc"] != null && dgvRow.Cells["dgvcbc"].Value != null && dgvRow.Cells.Count>0)
------解决方案--------------------if (dgvRow.Cells["dgvcbc"] != null && dgvRow.Cells["dgvcbc"].Value != null && dgvRow.Cells.Count>0)