本文介绍了我们如何添加一个datagridview的多个单元格的数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建用于制作帐单的datagridview。现在,我想添加所有第4列的值。我该怎么办?

I create a datagridview for making a bill. Now I want add all column 4 values. How can I do this?

推荐答案

 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

这篇关于我们如何添加一个datagridview的多个单元格的数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:31