gpt4 book ai didi

c# - 如何对datagridview末尾的列求和

转载 作者:太空宇宙 更新时间:2023-11-03 12:35:00 24 4
gpt4 key购买 nike

我想对 DataGridView 末尾的列求和,如下所示:

enter image description here

      column1 | column2  |column3|  column3   |
--------+----------+-------+------------|
1 | 2 | 3 | 4 |
---------+----------+-------+------------|
2 | 4 | 7 | 9 |
--------------+----------+-------+------------|
total 3 6 10 13
-----------------------------------------------

最佳答案

您可以在 gridview 的页脚添加总计:

 decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal>("Amount"));
GridView1.FooterRow.Cells[1].Text = "Total";
GridView1.FooterRow.Cells[1].HorizontalAlign = HorizontalAlign.Right;
GridView1.FooterRow.Cells[2].Text = total.ToString("N2");

关于c# - 如何对datagridview末尾的列求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41392636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com