如何在datagrid视图中对每行的值求和? [英] how to sum values per row in datagrid view?

查看:116
本文介绍了如何在datagrid视图中对每行的值求和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,





我怎样才能为两列添加每行值,然后结果可能在下一行或者datagridview中的第三列。 vb.net



提前谢谢,



Raz

Hi Experts,


How can i possibly add every row values for two column then the result could be in the next or third column in datagridview. vb.net

Thank you in advance,

Raz

推荐答案

感谢您澄清要求。



如果您想要附加数据,那么您可以在sql中而不是在sql中进行计算gridview ie



Thank you for clarifying the requirement.

If you want the additional data then you can do the calculation in the sql rather than within the gridview i.e.

sqL = "SELECT remittance_no, remit_date, messenger, item, item_value, rate.product, rate.product_value, rate.product_value * item_value as total_value FROM remittance INNER JOIN rate ON rate.product=remittance.item where rate.ratecode =@rcde and remittance.messenger =@msgr and remit_date between @dfrom and @dto"

然后

dgw.Rows.Add(dr("remittance_no"), dr("remit_date"), dr("messenger"), dr("item"), dr("item_value"), dr("product_value"), dr("total_value"))
 'not required now totalAmount += (dr("product_value") * dr("item_value"))



请注意,您可以使用DataTable直接从阅读器直接填充DataGridView,而不是循环:


Note that instead of the loop you can populate the DataGridView semi-directly from the reader using a DataTable :

Dim dt = new DataTable()
dt.Load(dr)
dgw.AutoGenerateColumns = True
dgw.DataSource = dt
dgw.Refresh()

信用 [ ^ ])


这篇关于如何在datagrid视图中对每行的值求和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆