110,535
社区成员
发帖
与我相关
我的任务
分享
#region 实现最后一行合计函数
public void TotalRow(DataGridView dataGridview1)
{
DataGridViewRow dgr = dataGridview1.Rows[dataGridview1.Rows.Count - 1];
dgr.ReadOnly = true;
dgr.DefaultCellStyle.BackColor = System.Drawing.Color.Khaki;
dgr.Cells[0].Value = "合计";
double db;
for (int i = 0; i < dataGridview1.Rows.Count - 1; i++)
{
try
{
db = Convert.ToDouble(dgr.Cells[4].Value) + Convert.ToDouble(dataGridview1.Rows[i].Cells[4].Value ??1);
dgr.Cells[4].Value = db.ToString("#0.00"); }
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
}
}
#endregion