6
Answers

Need Help with list boxes and general

dkusske

dkusske

20y
1.5k
1
Hello everybody, Im new here as of now. I just registered to get some help from you guys. I'm building this program that has a combo box and list box. In the combobox i have a list of items and their prices and when the item is selected from the dropdown the item is then copied over into the listbox. In the list box i have the items appearing and when i double click i want to get rid of the item. And when I single click i want to get a picture to show up. When the user has all of the items in the listbox and ready to purchase, the user then clicks on the calculate button and i want to get the total price of the items. I want to know how i can make this happen. So far i have this code. Private Sub Warehouse_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtUsername.SelectionStart = 0 txtPassword.SelectionStart = 0 Dim subtotal As Single Dim total As Single Dim gsttax As Single Dim pst As Single Dim grandtotal As Single With cboproducts.Items .Add("1000" & "World Industries Skateboarding" & vbTab & "$95") .Add("1002" & "Hollywood Skateboarding" & vbTab & "$90") .Add("1004" & "Birdhouse Skateboarding" & vbTab & "$100") .Add("1006" & "Status Skateboarding" & vbTab & "$60") .Add("1008" & "Element Skateboarding" & vbTab & "$105") .Add("1010" & "Foundation Skateboarding" & vbTab & "$85") .Add("1012" & "Black Label Skateboarding" & vbTab & "$80") .Add("1014" & "Chocolate Skateboarding" & vbTab & "$110") End With End Sub Private Sub cboproducts_SelectedIndexchanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboproducts.SelectedIndexChanged lstProducts.Items.Add(cboproducts.Text) 'cboproducts.Focus() End Sub Private Sub chkOntario_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkOntario.CheckedChanged Dim gsttax As Single If chkOntario.Checked = True Then gsttax = 1.08 Else gsttax = 1.0 End If End Sub Private Sub rboStandard_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rboStandard.CheckedChanged Dim choice As Integer Dim subtotal As Single If rboStandard.Checked = True Then subtotal = subtotal * 1.0 ElseIf rboDeluxe.Checked = True Then subtotal = subtotal * 1.2 Else : rboPremium.Checked = True subtotal = subtotal * 1.4 End If End Sub Private Sub txtUsername_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) ToolTip1.SetToolTip(txtUsername, "Enter your User Name") End Sub Private Sub txtPassword_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) ToolTip2.SetToolTip(txtPassword, "Enter your Password") End Sub Private Sub lstproducts_Selectionmode(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChanged Dim TabPos As Integer Dim TheItem As String TheItem = lstProducts.Text 'store the selected item 'find the position of vbTab in the clicked item TabPos = InStr(TheItem, vbTab) If Len(ItemsBot) = 0 Then 'first item, extract the item name ItemsBot = Microsoft.VisualBasic.Mid(TheItem, TabPos - 1) Else 'not the first item, add a comma, a CrLf 'and concatenate the new item ItemsBot = ItemsBot & ", " & vbCrLf & _ Microsoft.VisualBasic.Mid(TheItem, TabPos - 1) End If 'add the purchase price to total Total = Total + CSng(Val(Mid(TheItem, TabPos + 1))) End Sub Private Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalculate.Click If Len(ItemsBot) = 0 Then MsgBox("You have not selected any item yet.") Else MsgBox("You have purchased" & vbCrLf & ItemsBot & "." & vbCrLf _ & "The total is " & Format(Total, "Currency") & ".") ItemsBot = "" Total = 0 End If End Sub End Class
Answers (6)