[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
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
Re: How to move to next line in listview
It seems that the program loops infinitly
Re: How to move to next line in listview
can you post the exact code you're using?
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.
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 if
next
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
Re: How to move to next line in listview
frmMainS.LVItem should be just LVItem
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
Re: How to move to next line in listview
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))
Re: How to move to next line in listview
the lvItem declaration should be before:
+ not inside the if block
Re: How to move to next line in listview
yep. thanks! work's fine now. :)