如何在vb.net中计算2个单元格 [英] How to compute 2 cells in vb.net
问题描述
我正在寻找解决方案,但我找不到任何答案,请帮助我......
i我想要计算2个单元格显示总数..以下代码实际上很好并且只计算单行,我的问题是当我按下按钮2时我需要自动计算每一行......
Hi, Im searching for a solution but i can't find any answer, Please Help me...
i have 2 cells that i want to compute and display the total.. the below code is actually fine and compute only single row, my problem is i need to compute every row automatically when i press the button2...
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i As Integer = 0 To DataGridView2.RowCount - 1
Dim xQty As Double = CDbl(DataGridView2.Rows(i).Cells(8).Value)
Dim xPrc As Double = CDbl(DataGridView2.Rows(i).Cells(9).Value)
DataGridView2.Rows(i).Cells(10).Value = xQty * xPrc
Next
End Sub
例如:< br $> b $ b
for example:
Product--------Price--------Quantity--------Total Amount
Apple----------10.00-----------2---------------20
Banana---------20.00-----------3---------------20
Orange---------10.00------------5---------------30
第一行,当我更改价格时,苹果自动更改总金额并点击按钮..
但第二排和第三排什么都没发生。我需要在一次点击中计算每一行......感谢先进的
the first row, apple automatically change the total amount when i change the price and click the button..
but the second and third row nothing happened. i need to compute every row in just one click... thanks in advanced
推荐答案
看看 Computed Columns [ ^ ]
或单元格事件 [ ^ ]
帮助你。
如果你真的需要按钮更新,请尝试调用Datagridview2.Refresh和/或Aftervalidate循环结束。
See if Computed Columns[^]
or Cell events [^]
help you.
If you really need on button update, try calling Datagridview2.Refresh and/or Invalidate after the loop finishes.
Howdy All,
在for循环后尝试这个:
Dim cm作为CurrencyManager = Direct Cast(datqaGridView2.BindingContext(dataGridView2.DataSource),_ CurrencyManager)
cm.Refresh()
regs,< br $> b $ b
ron O。
Howdy All,
Try this after the for loop:
Dim cm As CurrencyManager = DirectCast(datqaGridView2.BindingContext(dataGridView2.DataSource), _ CurrencyManager)
cm.Refresh()
regs,
ron O.
这篇关于如何在vb.net中计算2个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!