总和DataGridView C#
我想显示标签
一列的所有单元格的 sum 的重新填充。我尝试了一个在网络中看到的代码,但代码不起作用。
这是代码:
foreach (DataGridViewRow row in dgv_Carrinho.Rows.Cast<DataGridViewRow>().Where(t => !string.IsNullOrEmpty(t.Cells["Valor"].Value?.ToString())))
{
lbl_Subtotal.Text += (Convert.ToDouble(row.Cells["Valor"].Value)).ToString();
}
有人可以帮我吗?
I would like to show into a label
the resul of the sum of all cells of one column. I tried one code that I saw in the net but the code doesnt work.
Here's the code:
foreach (DataGridViewRow row in dgv_Carrinho.Rows.Cast<DataGridViewRow>().Where(t => !string.IsNullOrEmpty(t.Cells["Valor"].Value?.ToString())))
{
lbl_Subtotal.Text += (Convert.ToDouble(row.Cells["Valor"].Value)).ToString();
}
Could someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须先计算总和,然后将其分配给
lbl_subtotal.text
,就像让我们尝试一些Linq操作一样,
You have to calculate sum first, then assign it to
lbl_Subtotal.Text
, something likeLets try some linq operations,
您可以为DataGridView使用添加扩展功能
:
u can add extension function for DataGridView
usage: