[RESOLVED] How to move to next line in listview-VBForums
Results 1 to 13 of 13

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

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Posts
    133

    Resolved [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. #2
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    18,361

    Re: How to move to next line in listview

    vb Code:
    1. Dim total(29) As Decimal
    2.  
    3. for q as integer = 0 to 29
    4.     Dim LVItem As New ListViewItem
    5.     LVItem.Text = PFlavor(q)
    6.     If Quantity(q) = 1 Then
    7.         LVItem.SubItems.Add("")
    8.         LVItem.SubItems.Add("")
    9.     Else
    10.         LVItem.SubItems.Add(price(q).ToString)
    11.         LVItem.SubItems.Add(Quantity(q).ToString)
    12.     End If
    13.     total(q) = price(q) * Quantity(q)
    14.     LVItem.SubItems.Add(total(q).ToString)
    15.     ListView1.Items.Add(LVItem)                  
    16. next

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Posts
    133

    Re: How to move to next line in listview

    It seems that the program loops infinitly

  4. #4
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    18,361

    Re: How to move to next line in listview

    can you post the exact code you're using?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Posts
    133

    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. #6
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    18,361

    Re: How to move to next line in listview

    vb Code:
    1. Dim total(29) As Decimal
    2.  
    3. for q as integer = 0 to 29
    4.     if PFlavor(q) <> "" then
    5.         Dim LVItem As New ListViewItem
    6.         LVItem.Text = PFlavor(q)
    7.         If Quantity(q) = 1 Then
    8.             LVItem.SubItems.Add("")
    9.             LVItem.SubItems.Add("")
    10.         Else
    11.             LVItem.SubItems.Add(price(q).ToString)
    12.             LVItem.SubItems.Add(Quantity(q).ToString)
    13.         End If
    14.         total(q) = price(q) * Quantity(q)
    15.         LVItem.SubItems.Add(total(q).ToString)
    16.         ListView1.Items.Add(LVItem)                  
    17.     end if
    18. next

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Posts
    133

    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. #8
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    18,361

    Re: How to move to next line in listview

    frmMainS.LVItem should be just LVItem

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Posts
    133

    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. #10
    Hyperactive Member
    Join Date
    Jan 2009
    Posts
    409

    Re: How to move to next line in listview

    wat is that pflavor ?
    Last edited by yogesh12; Feb 20th, 2010 at 11:48 PM.

  11. #11
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    18,361

    Re: How to move to next line in listview

    remove this:

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

    + change this:

    Dim LVItem As New ListViewItem(PFlavor(c))

  12. #12
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    18,361

    Re: How to move to next line in listview

    the lvItem declaration should be before:

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

    + not inside the if block

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Posts
    133

    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.