首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将数据网格视图多个单元格的数值相加?

如何将数据网格视图多个单元格的数值相加?
EN

Stack Overflow用户
提问于 2013-08-24 18:03:10
回答 1查看 108关注 0票数 0

我创建了一个用于创建账单的datagridview。现在我想要添加所有列4的值。我该怎么做呢?

EN

回答 1

Stack Overflow用户

发布于 2013-08-24 19:23:58

代码语言:javascript
复制
 Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        If e.ColumnIndex = 1 Then  // here your columnindex
            calctotal()
        End If
    End Sub
    Private Sub calctotal()
        Dim tot As Single
        For Each rw As DataGridViewRow In DataGridView1.Rows
            If rw.Cells(0).Value <> "" Then
                If String.IsNullOrEmpty(tot) Then
                    tot = Val(rw.Cells(0).Value) * Val(rw.Cells(1).Value)
                Else
                    tot = tot + Val(rw.Cells(0).Value) * Val(rw.Cells(1).Value)
                End If
                Label1.Text = tot
            End If
        Next
    End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18417333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档