简体   繁体   English

传递到c#中的文本框的Datagridview中整个列的总数

[英]total amount of the entire column in Datagridview passing to a textbox in c#

How can i get the overall total amount in the datagridview to a textbox in a same form? 如何以相同的形式将datagridview中的总金额发送到文本框?

// this part is calculating the total amount of a row
 private void SalesDataGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        if (SalesDataGrid != null)
        {
            for (int x = 0; x < SalesDataGrid.Rows.Count; x++)
            {
                SalesDataGrid.Rows[x].Cells[3].Value = Convert.ToInt32(SalesDataGrid.Rows[x].Cells[1].Value) *
                    Convert.ToDouble(SalesDataGrid.Rows[x].Cells[2].Value);

             //and i've tried this one below if it will work but it didn't do anything

            }
            if (SalesDataGrid != null)
            {
                for (int x = 0; x < SalesDataGrid.Rows.Count; x++)
                {
                    txtsalestotal.Text = SalesDataGrid.Rows[x].Cells[3].Value.ToString() ;
                }

            }

Try This: 尝试这个:

double totalAmount=0;
for (int x = 0; x < SalesDataGrid.Rows.Count; x++)
{
totalAmount += Convert.ToDouble(SalesDataGrid.Rows[x].Cells[3].Value.ToString());
}

txtsalestotal.Text=totalAmount.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM