how to get sum dynamically of datagridview column in textbox

后端 未结 5 996
时光说笑
时光说笑 2021-01-14 00:00

I want to get the sum of a column of datagridview and show that in textbox. After each entry the sum should be changed dynamically. For that I am using textChanged event of

5条回答
  •  无人共我
    2021-01-14 00:11

    this is the best simple way :

    private void your_name()
    {
    
        Double your_variable = dataGridView1.Rows.Cast().Sum(x => Convert.ToDouble(x.Cells["Column4"].Value));
    
        this.textBox1.Text = your_variable.ToString("N2");
    }
    

提交回复
热议问题