C# 如何打印动态创建最后一行的DataGridView?
我在DataGridView中动态创建了最后一个单元格/行,以显示成员总数和支付总额,但当我打印DataGridView时,不会打印最后一个单元格/行 我试图解决这个问题,但没有得到正确的结果。如何打印最后一个单元格/行 这是我在DataGridView中显示数据的代码:C# 如何打印动态创建最后一行的DataGridView?,c#,asp.net,C#,Asp.net,我在DataGridView中动态创建了最后一个单元格/行,以显示成员总数和支付总额,但当我打印DataGridView时,不会打印最后一个单元格/行 我试图解决这个问题,但没有得到正确的结果。如何打印最后一个单元格/行 这是我在DataGridView中显示数据的代码: private void button1_Click(object sender, EventArgs e) { SqlCommand cmdshow = new SqlCommand("select Regno,Fu
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmdshow = new SqlCommand("select Regno,Fullname,Contactno,Address,PaidAmt from NewMember", con);
SqlDataReader drshow = cmdshow.ExecuteReader();
dt = new DataTable();
dt.Load(drshow);
dataGridViewreport.DataSource = dt;
dataGridViewreport[3, dataGridViewreport.Rows.Count - 1].Value = "Total Sum";
dataGridViewreport[0, dataGridViewreport.Rows.Count - 1].Value = "Total Members";
int r;
for (r = 0; r < dataGridViewreport.Rows.Count - 1; r++)
{
DataGridViewRow row = dataGridViewreport.Rows[r];
}
double Total = 0;
for (int i = 0; i < dataGridViewreport.Rows.Count - 1; i++)
{
Total += Convert.ToDouble(dataGridViewreport.Rows[i].Cells["PaidAmt"].Value);
}
dataGridViewreport.Rows[dataGridViewreport.Rows.Count - 1].Cells["PaidAmt"].Value = Total;
dataGridViewreport.Rows[dataGridViewreport.Rows.Count - 1].Cells["Fullname"].Value = r;
}
private void button2_Click(object sender, EventArgs e)
{
DGVPrinter printer = new DGVPrinter();
printer.Title = "Member Report";
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.PrintDataGridView(dataGridViewreport);
}
该值是否显示在网格中?您不需要显示已注释的代码,它只会使视图混乱。