SUM过滤的DGV柱 [英] SUM Filtered DGV Column
本文介绍了SUM过滤的DGV柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有一个未绑定的DGV,我可以根据值隐藏行来过滤它。
我使用以下代码获取列的总和,它可以100%工作
Dim total =(从行在 我 .DataGridView2.Rows _
让 r = DirectCast (row,DataGridViewRow)_
其中r.Cells( ExclTot)。值 IsNot < span class =code-keyword> Nothing _
选择 CDec ( r.Cells( ExclTot)。Value))。总和
我 .Baskettot.Text = FormatCurrency(total)
唯一的问题是它还会计算隐藏的CELLS
有没有办法只在可见值上获得SUM?
我找到了BOUND DGV的解决方案,但请记住我的DGV是UNBOUND。
:(
解决方案
使用 DataGridViewRow.Visible [ ^ ]属性。
Dim total =(从行作为 DataGridViewRow 在 我 .DataGridView2.Rows _
其中r.Visible 和 r.Cells( ExclTot)。值 IsNot 没什么 _
选择 CDec (r.Cells( ExclTot)。值))。总和
或:
Dim visibleRowsSum = DataGridView2.Rows.OfType( Of DataGridViewRow)()。其中( Function (row)row.Visible 和 row.Cells( ExclTot)IsNot Nothing)。选择(函数(行)CDec(row.Cells( ExclTot)。值))。萨姆()
Hi Guys
I have an unbound DGV and i can filter it by hiding rows according to value.
I use the following code to get the SUM of column and it works 100%
Dim total = (From row In Me.DataGridView2.Rows _
Let r = DirectCast(row, DataGridViewRow) _
Where r.Cells("ExclTot").Value IsNot Nothing _
Select CDec(r.Cells("ExclTot").Value)).Sum
Me.Baskettot.Text = FormatCurrency(total)
Only problem is that it also calculates the hidden CELLS
Is there a way of getting the SUM only on visible values?
I have found solutions for BOUND DGV but take in mind my DGV is UNBOUND.
:(
解决方案
Use DataGridViewRow.Visible[^] property.
Dim total = (From row As DataGridViewRow In Me.DataGridView2.Rows _ Where r.Visible And r.Cells("ExclTot").Value IsNot Nothing _ Select CDec(r.Cells("ExclTot").Value)).Sum
or:
Dim visibleRowsSum = DataGridView2.Rows.OfType(Of DataGridViewRow)().Where(Function(row) row.Visible And row.Cells("ExclTot") IsNot Nothing).Select(Function(row) CDec(row.Cells("ExclTot").Value)).Sum()
这篇关于SUM过滤的DGV柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文