Public member 'Items' on type 'String' not found for loop listbox help

dragonx

Newcomer
Joined
Jul 11, 2012
Code:
Private Sub btnaddcart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddcart.Click

        Dim part As PartDescription = New PartDescription()
        part = CType(lbxItems.SelectedItem, PartDescription)
        Dim SItem As String
        Dim Updateqty As Boolean = False
        SItem = part.PartNumber
     
        MsgBox(SItem)
        For Each i As string In lstPart.Items
 
            If lstPart.SelectedItem.ToString = SItem Then
                Dim tempqty As Integer = Integer.Parse(lstQuantity.SelectedItem.Items.text)
                tempqty += 1
                lstQuantity.SelectedItem.Items.text = tempqty.ToString
                Updateqty = True
            End If
        Next

        If Updateqty = False Then
            lstPart.Items.Add(part.PartNumber)
            lstDescripption.Items.Add(part.PartName)
            lstUCost.Items.Add(part.UnitPrice)
            lstQuantity.Items.Add("1")
            lstUCost.Text = (part.UnitPrice * 1).ToString()
 
        End If
    End Sub

i have a bunch of listboxes one has the final item you select then press addtocart witch will take seprate parts of the string and add themm to the relevent listbox and have qty set to 1 what i want is if the same item is selected again is instead of making a dublicate is to increse the relevent qty in the qty listbox but i keep getting this error

Public member 'Items' on type 'String' not found


i know i could use a listview for this task instead but i wanted to do it with seprate listboxes any help would be appreciated thanks
 

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Location
USA
Step 1 is to use a debugger and figure out on which line the error is occurring. I'm going to guess it's this line:
Code:
Dim tempqty As Integer = Integer.Parse(lstQuantity.SelectedItem.Items.text)
Assuming the ListBox contains only strings, lstQuantity.SelectedItem is a string, which does not have a public member named Items.

This problem could probably have been avoided if you enabled Option Strict. I'm not going to go on a long rant about why it's bad to not use Option Strict, because there are already a million billion of those on the internet. All I'll say on the subject is that Option Strict is there for the sole reason of preventing errors.
 
Top Bottom