Definizione delle varie variabili nella classe principale:
codice:
Dim itm_ As ListViewItem
Dim itm As ListViewItem
Dim itm2 As ListViewItem
Dim itm3 As ListViewItem
Dim itm4 As ListViewItem
Dim list1 As ListViewItem
Dim list2 As ListViewItem
Dim list3 As ListViewItem
Dim str(5) As String
Dim str2(5) As String
Dim str3(5) As String
Dim str4(5) As String
Dim prezzo As String
Dim costofinale As Integer
Dim number As Integer
Dim number2 As Integer
Questo è il codice del pulsante aggiungi:
codice:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case number
Case 1
itm_ = ListView1.SelectedItems(0)
itm_.Remove()
list1 = ListView5.Items.Add(str(0))
list1.SubItems.Add((str(1)))
list1.SubItems.Add(NumericUpDown1.Value)
Case 2
itm2 = ListView2.SelectedItems(0)
itm2.Remove()
list2 = ListView5.Items.Add(str2(0))
list2.SubItems.Add((str2(1)))
list2.SubItems.Add(NumericUpDown1.Value)
Case 3
itm3 = ListView3.SelectedItems(0)
itm3.Remove()
list3 = ListView5.Items.Add(str3(0))
list3.SubItems.Add((str3(1)))
list3.SubItems.Add(NumericUpDown1.Value)
End Select
costofinale += ListView5.SelectedItems(0).SubItems(1).Text
TextBox1.Text = costofinale
Codice con cui carico il file txt contenenti i vari items:
codice:
Private Sub LoadList(ByVal lst As ListView, ByVal lst2 As ListView, ByVal lst3 As ListView, ByVal file As String) 'carica la lista dello shop
On Error GoTo err
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String
Dim f As String
FileOpen(1, file, OpenMode.Input)
While Not EOF(1)
Input(1, a) 'legge dal file
Input(1, b)
Input(1, c)
Input(1, d)
Input(1, e)
Input(1, f)
str(0) = a ' costruzioni
str(1) = b ' prezzo costruzioni
str2(0) = c ' hardware
str2(1) = d ' prezzo hardware
str3(0) = e ' engine
str3(1) = f ' prezzo engine
itm_ = New ListViewItem(str)
ListView1.Items.Add(itm_)
itm2 = New ListViewItem(str2)
ListView2.Items.Add(itm2)
itm3 = New ListViewItem(str3)
ListView3.Items.Add(itm3)
End While
FileClose(1)
Exit Sub
err:
MsgBox("Error: shop data, can't load settings", MsgBoxStyle.Critical)
End Sub
Codice con cui richiamo i vari Case del pulsante aggiungi
codice:
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
number = 1
End Sub
Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged
number = 2
End Sub
Private Sub ListView3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView3.SelectedIndexChanged
number = 3
End Sub