locked
Splitting ListBox Items into other ListBoxes RRS feed

  • Question

  • I am trying to have a list of items inside a main listbox, split into 4 other listboxes, splitting by line.

     

    For Example

    Listbox1 Contains:

    1

    2

    3

    4

    5

    6

    7

    8

     

    8 different lines, each line has something in it, i want to split each line, into another listbox, therefor there would be 4 listboxes that would have things split into them from listbox 1

     

    it would end up being like

     

    Listbox 1 (the main one)

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

     

    Listbox2

    1

    5

    9

    Listbox3

    2

    6

    10

    Listbox4

    3

    7

    11

    Listbox5

    4

    8

    12

     

    Each line will be split into  a different listbox, first line = listbox 2, second line = listbox 3, third line = listbox 4, fourth line = listbox 5, then it will repeat for the next lines following

     

    i just have no idea how to do this, any help would be good xd

    Tuesday, November 16, 2010 9:58 AM

Answers

  • I have changed the Code due to some errors and tested in mi machine:

     

     

     

     Dim counterListBox As Integer = 2
    
        Dim counterItems As Integer = 0
    
        Dim Liste As ListBox
    
        For counterItems = 0 To ListBox1.Items.Count - 1
    
          Liste = CType(Me.Controls.Find(String.Format("ListBox{0}", counterListBox), True)(0), ListBox)
    
          Liste.Items.Add(ListBox1.Items(counterItems))
    
          If counterListBox < 5 Then
    
            counterListBox += 1
    
          Else
    
            counterListBox = 2
    
          End If
    
    
    
        Next
    
    I have tested and it works fine.
    Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
    Si la respuesta te ha sido util Votala.
    Mi Blog: Jtorrecilla
    Enlace a Faq de Winforms en Ingles Muy bueno
    • Proposed as answer by Heslacher Tuesday, November 16, 2010 11:17 AM
    • Marked as answer by Bsk8r Wednesday, November 17, 2010 1:27 AM
    Tuesday, November 16, 2010 11:03 AM

All replies

  • You need to do something like this:

     

    Dim counterListBox as integer=1

    dim counterItems as integer=0

    dim Liste as ListBox

    for counterItems to ListBox1.items.count

    Liste= ctype(Me.Controls.Find(String.Format("ListBox{0}",counterListBox ),True)(0),ListBox)

    Liste.add(ListBox1.items(counterItems))

    if counterListBox<5 then

    counterListBox+=1

    else

     counterListBox=2

    end if

     

    next


    Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
    Si la respuesta te ha sido util Votala.
    Mi Blog: Jtorrecilla
    Enlace a Faq de Winforms en Ingles Muy bueno
    Tuesday, November 16, 2010 10:08 AM
  • Tried to use that somehow and all it did was spam the first number into the listbox...
    Tuesday, November 16, 2010 10:51 AM
  • I have changed the Code due to some errors and tested in mi machine:

     

     

     

     Dim counterListBox As Integer = 2
    
        Dim counterItems As Integer = 0
    
        Dim Liste As ListBox
    
        For counterItems = 0 To ListBox1.Items.Count - 1
    
          Liste = CType(Me.Controls.Find(String.Format("ListBox{0}", counterListBox), True)(0), ListBox)
    
          Liste.Items.Add(ListBox1.Items(counterItems))
    
          If counterListBox < 5 Then
    
            counterListBox += 1
    
          Else
    
            counterListBox = 2
    
          End If
    
    
    
        Next
    
    I have tested and it works fine.
    Para el correcto funcionamiento, y que otros usuarios se puedan beneficiar de la solucion de esta pregunta por favor marca las respuestas que te hayan ayudado como "Respuesta".
    Si la respuesta te ha sido util Votala.
    Mi Blog: Jtorrecilla
    Enlace a Faq de Winforms en Ingles Muy bueno
    • Proposed as answer by Heslacher Tuesday, November 16, 2010 11:17 AM
    • Marked as answer by Bsk8r Wednesday, November 17, 2010 1:27 AM
    Tuesday, November 16, 2010 11:03 AM