0
See pic我對vb.net不熟悉。所以,我試圖做的是當我點擊選擇的產品,我把數量。總價格將顯示列表視圖中數量和價格的乘積值。我把情況2的代碼,因爲它是價格,但是當我運行它,它顯示0,然後當我改變它的值爲2,它不會乘。這裏是我到目前爲止的代碼:如何將文本框中的值與列表視圖中的列相乘?
Imports System.Data.SqlClient
Imports System.IO
Public Class Form2
Dim con As SqlConnection = New SqlConnection("server=.\SQL;database=try;Trusted_Connection=TRUE")
Dim cmd As SqlCommand
Dim cmd2 As SqlCommand
Dim rdr As SqlDataReader
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.Open()
con.Close()
list()
End Sub
Sub list()
con.Open()
cmd = New SqlCommand("SELECT * FROM ProductTable", con)
rdr = cmd.ExecuteReader
ListView1.Items.Clear()
If rdr.HasRows Then
Do While rdr.Read()
Dim arr As String() = New String(2) {}
Dim itm As ListViewItem
arr(0) = rdr("productID")
arr(1) = rdr("product")
arr(2) = rdr("price")
itm = New ListViewItem(arr)
ListView1.Items.Add(itm)
Loop
End If
con.Close()
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
With Me.ListView1
Dim i As Integer
For Each item As ListViewItem In ListView1.SelectedItems
i = item.Index
Next
Dim innercounter As Integer = 0
For Each subItem As ListViewItem.ListViewSubItem In ListView1.Items(i).SubItems
Dim myString As String = ListView1.Items(i).SubItems(innercounter).Text
Select Case innercounter
Case 2
txtqty.Text = 0.ToString()
txtqty.Text = CType(0, String)
txtqty.Text = CStr(0)
txtqty.Text = "0"
txtprice.Text = myString * txtqty.Text
End Select
innercounter += 1
Next
End With
End Sub
End Class
集'選項嚴格On'文本控件包含文本。他們不是數字,除非你轉換成數字,否則不能相乘。文本控件通常還需要用戶輸入,這在表單加載中不會發生。與選擇ListView項目相同。這些全局數據庫提供者對象也會引起你的頭痛。閱讀[問]並參加[遊覽] – Plutonix
您必須將'strings'轉換爲'integer' –