Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何打印动态创建最后一行的DataGridView?_C#_Asp.net - Fatal编程技术网

C# 如何打印动态创建最后一行的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

我在DataGridView中动态创建了最后一个单元格/行,以显示成员总数和支付总额,但当我打印DataGridView时,不会打印最后一个单元格/行

我试图解决这个问题,但没有得到正确的结果。如何打印最后一个单元格/行

这是我在DataGridView中显示数据的代码:

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);
  }

该值是否显示在网格中?您不需要显示已注释的代码,它只会使视图混乱。