How to fill a listbox from a checklistbox in MS Visual Basic?

0

Good companions, it turns out that I'm doing a program in MS Visual Basic where I have a checklistbox that is filled from a combobox , which according to what I choose in the combobox the list is generated in the checklistbox by clicking on a button, what I want to do now is that what I select in the checklistbox take out the names and put them in a listbox apart from what I have, is it possible to do this with a cycle ?, how could I do it ?. I attach image of my form.

Button code generate list:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If comboescalafon.SelectedIndex = 0 Then
            lista.Items.Add("kevin")
            lista.Items.Add("jeison")


        ElseIf comboescalafon.SelectedIndex = 1 Then
            Button2.Enabled = True
            lista.Items.Add("pablo")
            lista.Items.Add("andres")
            lista.Items.Add("douglas")
            lista.Items.Add("chepo")

        ElseIf comboescalafon.SelectedIndex = 2 Then
            Button2.Enabled = True
            lista.Items.Add("caralos")
            lista.Items.Add("camila")
            lista.Items.Add("jose")
            lista.Items.Add("estela")
            lista.Items.Add("harold")
            lista.Items.Add("jhon")


        ElseIf comboescalafon.SelectedIndex = 3 Then
            Button2.Enabled = True
            lista.Items.Add("felipe")
        ElseIf comboescalafon.SelectedIndex = 4 Then
            Button2.Enabled = True
            lista.Items.Add("juan")
            lista.Items.Add("manuel")
            lista.Items.Add("gers")
        ElseIf comboescalafon.SelectedIndex = 5 Then
            Button2.Enabled = True
            lista.Items.Add("juan")
            lista.Items.Add("daniel")
        ElseIf comboescalafon.SelectedIndex = 6 Then
            Button2.Enabled = True
            lista.Items.Add("alejandro")
        ElseIf comboescalafon.SelectedIndex = 7 Then
            Button2.Enabled = True
            lista.Items.Add("homero")
            lista.Items.Add("maguie")
            lista.Items.Add("lissa")
        ElseIf comboescalafon.SelectedIndex = 8 Then
            Button2.Enabled = True
            lista.Items.Add("bart")

        End If




    End Sub

I would like to add the functionality that I mention to you in the add button that is in my form.

    
asked by Ándres Felipe Patiño 26.01.2018 в 22:01
source

1 answer

0

Basically what you would do is make a for to retrieve all the data you have selected and then put them in the list (list1).

Change that name with the one you have for your ListBox and it should work.

Logically you have to put this code in the button that you use to load your list. (Add button)

I hope you serve

       Dim i As Integer    
        For i = 0 To (lista.Items.Count - 1)
            If lista.GetItemChecked(i) = True Then
                lista1.Items.Add(lista.Items(i).ToString)
            End If
        Next
    
answered by 26.01.2018 / 22:54
source