Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to add Listview subitem with For Loop

How to add Listview subitem with For Loop

Scheduled Pinned Locked Moved Visual Basic
helptutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kurja kurdoh
    wrote on last edited by
    #1

    Dear Expert, I have a Listview with subitem which i add populate data in listview which is lengthy, i want to shorten the code, i tried For loop but it give me error at run time. With Do loop it working.

    Do Until rs.EOF = True
    Set LI = ListView1.ListItems.Add(, , rs(0))

                    'For x = 1 To 16
                        'LI.SubItems(i) = rs(x)
                        
                    'Next x
                   
                        LI.SubItems(1) = rs(1)
                        LI.SubItems(2) = rs(2)
                        LI.SubItems(3) = rs(3)
                        LI.SubItems(4) = rs(4)
                        LI.SubItems(5) = rs(5)
                        LI.SubItems(6) = rs(6)
                        LI.SubItems(7) = rs(7)
                        LI.SubItems(8) = rs(8)
                        LI.SubItems(9) = rs(9)
                        LI.SubItems(10) = rs(10)
                        LI.SubItems(11) = rs(11)
                        LI.SubItems(12) = rs(12)
                        LI.SubItems(13) = rs(13)
                        LI.SubItems(14) = rs(14)
                        LI.SubItems(15) = rs(15)
                        LI.SubItems(16) = rs(16)
                    rs.MoveNext
                Loop
    
    L 1 Reply Last reply
    0
    • K kurja kurdoh

      Dear Expert, I have a Listview with subitem which i add populate data in listview which is lengthy, i want to shorten the code, i tried For loop but it give me error at run time. With Do loop it working.

      Do Until rs.EOF = True
      Set LI = ListView1.ListItems.Add(, , rs(0))

                      'For x = 1 To 16
                          'LI.SubItems(i) = rs(x)
                          
                      'Next x
                     
                          LI.SubItems(1) = rs(1)
                          LI.SubItems(2) = rs(2)
                          LI.SubItems(3) = rs(3)
                          LI.SubItems(4) = rs(4)
                          LI.SubItems(5) = rs(5)
                          LI.SubItems(6) = rs(6)
                          LI.SubItems(7) = rs(7)
                          LI.SubItems(8) = rs(8)
                          LI.SubItems(9) = rs(9)
                          LI.SubItems(10) = rs(10)
                          LI.SubItems(11) = rs(11)
                          LI.SubItems(12) = rs(12)
                          LI.SubItems(13) = rs(13)
                          LI.SubItems(14) = rs(14)
                          LI.SubItems(15) = rs(15)
                          LI.SubItems(16) = rs(16)
                      rs.MoveNext
                  Loop
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2
              LI.SubItems(i) = rs(x)
      

      What is the value of i in this statement?

      K 1 Reply Last reply
      0
      • L Lost User
                LI.SubItems(i) = rs(x)
        

        What is the value of i in this statement?

        K Offline
        K Offline
        kurja kurdoh
        wrote on last edited by
        #3

        Dear Sir, is this the right path to display listview subitems with for loop

        Li.SubItems(x) = rs(x)

        L 1 Reply Last reply
        0
        • K kurja kurdoh

          Dear Sir, is this the right path to display listview subitems with for loop

          Li.SubItems(x) = rs(x)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          What happens when you try it?

          K 1 Reply Last reply
          0
          • L Lost User

            What happens when you try it?

            K Offline
            K Offline
            kurja kurdoh
            wrote on last edited by
            #5

            Dear Sir, It work. But i just want to know it will affect the other program when compile or not.

            L 1 Reply Last reply
            0
            • K kurja kurdoh

              Dear Sir, It work. But i just want to know it will affect the other program when compile or not.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              kurja-kurdoh wrote:

              i just want to know it will affect the other program

              In what way affect other program? All you are doing is adding items into a list.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups