如何在datagridview中找到sum [英] how find sum in datagridview

查看:106
本文介绍了如何在datagridview中找到sum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的项目。这是关于糕点店的比尔管理系统。我将在一栏中输入单价和每个糕点的编号。最后一个单元格是净价。我需要找到净值。(单价*没有糕点​​)

请帮帮我。抱歉英语不好

I have simple project. It's about Bill Management System for pastry shop. I will input the unit price and the no of each pastries in one column. The last cell is net price. I need find net value.(unit price*no of pastries)
Pls help me. sorry for poor English

推荐答案

Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
       If e.ColumnIndex = 1 Then
           DataGridView1.Rows(e.RowIndex).Cells(2).Value = Val(DataGridView1.Rows(e.RowIndex).Cells(0).Value) * Val(DataGridView1.Rows(e.RowIndex).Cells(1).Value)
           TotalCal()
       End If
   End Sub
   Private Sub TotalCal()
       Dim tot As Single
       For Each rw As DataGridViewRow In DataGridView1.Rows
           If Not String.IsNullOrEmpty(rw.Cells(0).Value) Then
               tot = tot + Val(rw.Cells(2).Value)
           End If
       Next
       Label1.Text = tot
   End Sub





尝试此代码对您有用



Try this code useful to you


好了,请参阅此链接。它是一个关于在页脚中显示总和的例子。您可以了解如何操作并相应地修改您的逻辑。



在asp.net的gridview页脚中显示总列数总和 [ ^ ]



问候:笑:
Well,refer to this link. Its an example regarding displaying sum in the footer. You can get idea on how to do it and modify your logic accordingly.

Display sum of columns total in gridview footer in asp.net[^]

Regards :laugh:


这篇关于如何在datagridview中找到sum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆