vb.net - “是否有在鼠标指针选择时查找 DataGridView 中列值总和的功能?”
问题描述
我可以通过将鼠标拖动到它们上来计算 DataGridView 中列的选定单元格值的总和。
我尝试了以下代码,但它对我不起作用。
`Private Sub grid1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grid1.SelectionChanged
Try
Dim sum As Double = 0
For Each row As DataGridViewRow In grid1.SelectedRows
sum += Convert.ToDouble(row.Cells("Item Rate").Value)
Next
txtCr.TextboxValue = sum.ToString()
Catch ex As Exception
End Try
End Sub
解决方案
多亏了吉米
Private Sub grid1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grid1.SelectionChanged
Try
Dim SUM As Double = 0
For Each cell As DataGridViewCell In grid1.SelectedCells
If cell.ColumnIndex() Then
SUM += Convert.ToDouble(cell.Value)
End If
Next
txtCr.TextboxValue = SUM.ToString()
Catch ex As Exception
End Try
End Sub
结束类
推荐阅读
- flutter - 由于上述问题,无法构建插件 shared_preferences
- android - 如何让以下外键在firebase中工作
- r - 将 survfit() 应用于生存对象列表
- audio - 如何在不改变质量和不改变帧率(Ffmpeg)的情况下压缩视频大小?
- vulkan - 为什么 vulkan 子通道内容不能同时是内联和辅助命令缓冲区?
- reactjs - npm 在 create-react-app 后开始显示错误
- node.js - MongoDB:如何使用条件递归获取所有子节点的计数?
- java - Maven 在构建我们自己的 custom.jar 时发布和使用第三方运行时 jar
- sql - 在 BigQuery 中获取在同一天安装和卸载应用程序的用户以及卸载时间
- amazon-web-services - Fargate 服务的启动类型与容量提供者策略