[当我删除DataGridView中的项目时如何调整价格(不与任何数据库连接)Vb.net

问题描述 投票:0回答:1

当我在数据网格视图中删除项目时,我试图调整小计(不连接任何数据库。

`

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                Me.DataGridView1.Rows.Add("H.Burger", "10.90")
                Subtotal = Subtotal + "RM10.9"
                Me.Label13.Text = Subtotal.ToString()
            End Sub
            Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
                Me.DataGridView1.Rows.Add("S.Carborana", "12.90")
                Subtotal = Subtotal + 12.9
                Me.Label13.Text = Subtotal.ToString()
            End Sub
            Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
                Me.DataGridView1.Rows.Add("N.Lemak", "5.90")
                Subtotal = Subtotal + 5.9
                Me.Label13.Text = Subtotal.ToString()
            End Sub
            Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
                Me.DataGridView1.Rows.Add("CurryMee", "7.90")
                Subtotal = Subtotal + 7.9
                Me.Label13.Text = Subtotal.ToString()
            End Sub
            Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
                Me.DataGridView1.Rows.Add("CCRice", "8.90")
                Subtotal = Subtotal + 8.9
                Me.Label13.Text = Subtotal.ToString()
            End Sub
vb.net
1个回答
0
投票

您可以尝试下面的代码

Private Sub AdjustPrice()
        Dim price As Decimal = 0
        For x = 0 To [your Datagridview name].Rows.Count - 1
            If Not IsDBNull([your Datagridview name].Rows(x).Cells([your cell goes here]).Value) Then price = price + [your Datagridview name].Rows(x).Cells([your cell goes here]).Value
        Next
        lblPrice.Text = FormatCurrency(sum.ToString())
    End Sub
© www.soinside.com 2019 - 2024. All rights reserved.