vb.net - 如何添加我在 ListView CheckBox 中选中的项目的值
问题描述
我正在做一个学校项目,并且发现自己在这种情况下困了多少天了。我找不到在 ListView 中添加选中项的值的方法。
我找到了一种在不检查 CheckBox 的情况下添加它们的方法,但是如果我检查了 CheckBox 中的项目,我正在寻找一种添加它们的方法。
Module PaymentControllerModule
Public Sub TotalFeeValue()
Dim query As String = "SELECT * FROM tbl_fees"
Dim totalfees As Double
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
Dim table As New DataTable
Dim i As Integer
Dim o As Integer
With command
.CommandText = query
.Connection = databaseconnect
End With
With adapter
.SelectCommand = command
.Fill(table)
End With
formPaymentsDynamic.Lv_Paymentfees.Items.Clear()
For i = 0 To table.Rows.Count - 1
With formPaymentsDynamic.Lv_Paymentfees
.Items.Add(table.Rows(i)("fee_description"))
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("fee_price"))
End With
End With
totalfees += Val(table.Rows(i)("fee_price"))
formPaymentsDynamic.txtTotalAmount.Text = totalfees
Next
End Sub
End Module
我期望在 ListView 中检查的总和项目的输出,但即使不检查它们,我也只能做所有项目的总和值。我希望你能帮助我。
这是程序的示例输出,即使没有检查,我也设法在 ListView 中添加值。
解决方案
您必须遍历Listview
而不是数据表中的已检查项目。您的代码可能类似于:
For Each item As ListViewItem In YourListView.CheckedItems
totalfees += CDbl( item.SubItems("fee_price").Text)
Next
推荐阅读
- javascript - 返回承诺的Javascript顺序函数
- php - 数据库已连接,但数据未存储在 xamp 服务器中
- android - 切换到多窗口模式时,我的 Android 应用程序崩溃
- ios - iOS当按下按钮“下一步”加载新行表单解析Swift
- python - Python中各种数据库的单一API
- java - 从 Fragment 中的 Adapter 获取 imageview
- git - git clone 或通过慢速网络拉取一个巨大的 repo 以致命的 EOF 结束
- dataframe - Deedle F# - 查找索引组中的最大行数
- php - 将 curl 命令转换为 PHP 用于 csv->Excel 转换器
- git - 没有用户名的 git pull 问题