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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. List box loop?

List box loop?

Scheduled Pinned Locked Moved Visual Basic
question
8 Posts 3 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.
  • C Offline
    C Offline
    China Gary
    wrote on last edited by
    #1

    How would i code a loop to go through a listbox and take each value out of it to insert the values into textboxes? Would i use a loop? Dim strLan As String strLan = lstX.SelectedIndex() = 0 txtX.Text = strLan This code isnt working for me, somthing pretty damn basic i know!

    M N 2 Replies Last reply
    0
    • C China Gary

      How would i code a loop to go through a listbox and take each value out of it to insert the values into textboxes? Would i use a loop? Dim strLan As String strLan = lstX.SelectedIndex() = 0 txtX.Text = strLan This code isnt working for me, somthing pretty damn basic i know!

      M Offline
      M Offline
      MatrixCoder
      wrote on last edited by
      #2

      Yes, you would use a loop like this:

      For Each strLan As String In lstX.Items
      txtX.Text += strLan
      Next


      Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

      1 Reply Last reply
      0
      • C China Gary

        How would i code a loop to go through a listbox and take each value out of it to insert the values into textboxes? Would i use a loop? Dim strLan As String strLan = lstX.SelectedIndex() = 0 txtX.Text = strLan This code isnt working for me, somthing pretty damn basic i know!

        N Offline
        N Offline
        nlarson11
        wrote on last edited by
        #3

        Ex: puts all the values into 1 textbox. For i As Int16 = 0 To ListBox1.Items.Count - 1 TextBox1.Text += ListBox1.Items(i).ToString Next not sure how you plan on managing the number of textboxes on the form because depending on the number of items in the listbox, it could get out of hand...

        C 1 Reply Last reply
        0
        • N nlarson11

          Ex: puts all the values into 1 textbox. For i As Int16 = 0 To ListBox1.Items.Count - 1 TextBox1.Text += ListBox1.Items(i).ToString Next not sure how you plan on managing the number of textboxes on the form because depending on the number of items in the listbox, it could get out of hand...

          C Offline
          C Offline
          China Gary
          wrote on last edited by
          #4

          Thanks for the help! Thing is, i have up to 8 in the list box, and each element in that listbox is to go to a different textbox. Sorry, but i just cant figure it out! Thanks!

          N 1 Reply Last reply
          0
          • C China Gary

            Thanks for the help! Thing is, i have up to 8 in the list box, and each element in that listbox is to go to a different textbox. Sorry, but i just cant figure it out! Thanks!

            N Offline
            N Offline
            nlarson11
            wrote on last edited by
            #5

            let's step back and see what you really want to do... 1) how does the listbox get fed? (what dictates 'up to 8') 2) are you creating the textboxes on the fly or are all 8 on the form all the time?

            C 1 Reply Last reply
            0
            • N nlarson11

              let's step back and see what you really want to do... 1) how does the listbox get fed? (what dictates 'up to 8') 2) are you creating the textboxes on the fly or are all 8 on the form all the time?

              C Offline
              C Offline
              China Gary
              wrote on last edited by
              #6

              Sorry for the delay! Basically i have a list box populated with items from another listbox, drag and drop basically. Within a different groupbox, i have 8 different textboxes. How do i take the first element from the listbox and put it into the first textbox, second to second etc... They are all on the form at the same time. Can a loop easily do this? Thanks

              N 1 Reply Last reply
              0
              • C China Gary

                Sorry for the delay! Basically i have a list box populated with items from another listbox, drag and drop basically. Within a different groupbox, i have 8 different textboxes. How do i take the first element from the listbox and put it into the first textbox, second to second etc... They are all on the form at the same time. Can a loop easily do this? Thanks

                N Offline
                N Offline
                nlarson11
                wrote on last edited by
                #7

                I see 2 "simple" options...(there are more complex but I dont' have time to show you how to do these) 1) manually check the index of the for next loop assign it to each associated textbox ex: for i as int16 = 0 to listbox1.items.count-1 select case i case 0: textbox1.text = listbox1.items(i).tostring case 1: textbox2.text = listbox1.items(i).tostring . . end select next 2) put the index in the tag property of each textbox ex: textbox1.tag = "0" textbox2.tag = "1" etc. for i as int16 = 0 to listbox1.items.count-1 for each oCtrl as control in me.controls if typeof(octrl) is textbox then with ctype(octrl,textbox) if .tag = i.tostring then .text = listbox1.items(i).tostring exit for end if end with end if next next

                C 1 Reply Last reply
                0
                • N nlarson11

                  I see 2 "simple" options...(there are more complex but I dont' have time to show you how to do these) 1) manually check the index of the for next loop assign it to each associated textbox ex: for i as int16 = 0 to listbox1.items.count-1 select case i case 0: textbox1.text = listbox1.items(i).tostring case 1: textbox2.text = listbox1.items(i).tostring . . end select next 2) put the index in the tag property of each textbox ex: textbox1.tag = "0" textbox2.tag = "1" etc. for i as int16 = 0 to listbox1.items.count-1 for each oCtrl as control in me.controls if typeof(octrl) is textbox then with ctype(octrl,textbox) if .tag = i.tostring then .text = listbox1.items(i).tostring exit for end if end with end if next next

                  C Offline
                  C Offline
                  China Gary
                  wrote on last edited by
                  #8

                  thanks, ill give it a go!

                  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