在我的表单上,我有一个标签 (lblBalance),我有一个从 Access 数据库填充的 DGV。如果我添加、删除或更新一行,如何刷新标签文本以反映新余额?
到目前为止,这是我的 frmMain 代码:
Public Class frmMain
Private Sub TransactionsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransactionsBindingNavigatorSaveItem.Click
Me.Validate()
Me.TransactionsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CheckingDataSet)
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CheckingDataSet.Transactions' table. You can move, or remove it, as needed.
Me.TransactionsTableAdapter.Fill(Me.CheckingDataSet.Transactions)
lblTotalCredits.Text = BalanceTotal().ToString("c")
End Sub
Private Function BalanceTotal() As Double
Dim tot As Double = 0
Dim i As Integer = 0
For i = 0 To TransactionsDataGridView.Rows.Count - 1
tot = tot + Convert.ToDouble(TransactionsDataGridView.Rows(i).Cells(3).Value)
Next i
Return tot
End Function
End Class