[RESOLVED] How to move to next line in listview-VBForums

# Thread: [RESOLVED] How to move to next line in listview

1. ## [RESOLVED] How to move to next line in listview

. How do I proceed to the next line in list view? my code is

Code:
```        Dim LVItem As New ListViewItem
Dim total(29) As Decimal
Dim q As Integer
If q <= 29 Then
LVItem.Text = PFlavor(q)
If Quantity(q) = 1 Then
LVItem.SubItems.Add("".ToString)
LVItem.SubItems.Add("".ToString)
Else
LVItem.SubItems.Add(price(q).ToString)
LVItem.SubItems.Add(Quantity(q).ToString)
End If
total(q) = price(q) * Quantity(q)
LVItem.SubItems.Add(total(q).ToString)
ListView1.Items.Add(LVItem)
q += 1
End If
q = 0```

2. ## Re: How to move to next line in listview

vb Code:
`Dim total(29) As Decimal for q as integer = 0 to 29    Dim LVItem As New ListViewItem    LVItem.Text = PFlavor(q)    If Quantity(q) = 1 Then        LVItem.SubItems.Add("")        LVItem.SubItems.Add("")    Else        LVItem.SubItems.Add(price(q).ToString)        LVItem.SubItems.Add(Quantity(q).ToString)    End If    total(q) = price(q) * Quantity(q)    LVItem.SubItems.Add(total(q).ToString)    ListView1.Items.Add(LVItem)                   next`

3. ## Re: How to move to next line in listview

It seems that the program loops infinitly

4. ## Re: How to move to next line in listview

can you post the exact code you're using?

5. ## Re: How to move to next line in listview

My bad. it's ok now. Uhm.. How do you prevent the program from displaying empty arrays? Say if (4) and so on is empty.

6. ## Re: How to move to next line in listview

vb Code:
`Dim total(29) As Decimal for q as integer = 0 to 29    if PFlavor(q) <> "" then        Dim LVItem As New ListViewItem        LVItem.Text = PFlavor(q)        If Quantity(q) = 1 Then            LVItem.SubItems.Add("")            LVItem.SubItems.Add("")        Else            LVItem.SubItems.Add(price(q).ToString)            LVItem.SubItems.Add(Quantity(q).ToString)        End If        total(q) = price(q) * Quantity(q)        LVItem.SubItems.Add(total(q).ToString)        ListView1.Items.Add(LVItem)                       end ifnext`

7. ## Re: How to move to next line in listview

Thanks. it works now. i've got another question. I want to update the listview from another form. So far, i can only write 1 line. if I try to enter a new line, and error pops up saying i can't over write the line. Also, the line breaks at the 2nd column. May I know which code breaks the line?

Code:
```        Dim total(29) As Decimal
Quantity(c) = txtQuantity.Text
frmMainS.ListView1.Items.Add(PFlavor(c))
If Quantity(c) <> 0 Then
If Quantity(c) = 1 Then
Dim LVItem As New ListViewItem
frmMainS.LVItem.SubItems.Add("")
frmMainS.LVItem.SubItems.Add("")
Else
frmMainS.LVItem.SubItems.Add(price(c).ToString)
frmMainS.LVItem.SubItems.Add(Quantity(c).ToString)
End If
total(c) = price(c) * Quantity(c)
frmMainS.LVItem.SubItems.Add(total(c).ToString)
frmMainS.ListView1.Items.Add(frmMainS.LVItem)
c += 1
End If```

8. ## Re: How to move to next line in listview

frmMainS.LVItem should be just LVItem

9. ## Re: How to move to next line in listview

Thanks. but the line still breaks at the 2nd column. The subitems are written on the following line

10. ## Re: How to move to next line in listview

wat is that pflavor ?

11. ## Re: How to move to next line in listview

remove this:

vb Code:
`frmMainS.ListView1.Items.Add(PFlavor(c))`

+ change this:

Dim LVItem As New ListViewItem(PFlavor(c))

12. ## Re: How to move to next line in listview

the lvItem declaration should be before:

vb Code:
`If Quantity(c) = 1 Then`

+ not inside the if block

13. ## Re: How to move to next line in listview

yep. thanks! work's fine now.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured

Click Here to Expand Forum to Full Width

Survey posted by VBForums.