Control ListBox Visual Basic
Manejo de Listas control ListBox - Visual Basic 2010
Código fuente del formulario:
Private Sub btntodos1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntodos1.Click
Dim i As Integer
If lsttabla1.Items.Count > 0 Then 'Si no está en vacio la lista
'Recorremos el ListBox1
For i = 0 To lsttabla1.Items.Count - 1
lsttabla2.Items.Add(lsttabla1.Items(i))
Next
'Borramos la lista
lsttabla1.Items.Clear()
End If
'cuenta los valores de la lista
txttotal1.Text = lsttabla1.Items.Count
txttotal2.Text = lsttabla2.Items.Count
End Sub
Private Sub btnadd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd1.Click
lsttabla1.Items.Add(txtvalor1.Text)
txtvalor1.Clear()
txtvalor1.Focus()
'cuenta los valores de la lista
txttotal1.Text = lsttabla1.Items.Count
End Sub
Private Sub btnadd2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd2.Click
lsttabla2.Items.Add(txtvalor2.Text)
txtvalor2.Clear()
txtvalor2.Focus()
'cuenta los valores de la lista
txttotal2.Text = lsttabla2.Items.Count
End Sub
Private Sub btnuno1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuno1.Click
Dim valor As String
valor = lsttabla1.SelectedItem
lsttabla2.Items.Add(valor)
lsttabla1.Items.Remove(valor)
'cuenta los valores de la lista
txttotal2.Text = lsttabla2.Items.Count
txttotal1.Text = lsttabla1.Items.Count
End Sub
Private Sub btntodos2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntodos2.Click
Dim valor As String
valor = lsttabla2.SelectedItem
lsttabla1.Items.Add(valor)
lsttabla2.Items.Remove(valor)
'cuenta los valores de la lista
txttotal1.Text = lsttabla1.Items.Count
txttotal2.Text = lsttabla2.Items.Count
End Sub
Private Sub btnuno2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuno2.Click
Dim i As Integer
If lsttabla2.Items.Count > 0 Then 'Si no está vacio la lista
'Recorremos el ListBox2
For i = 0 To lsttabla2.Items.Count - 1
lsttabla1.Items.Add(lsttabla2.Items(i))
Next
'Borramos la lista
lsttabla2.Items.Clear()
End If
'cuenta los valores de la lista
txttotal2.Text = lsttabla2.Items.Count
txttotal1.Text = lsttabla1.Items.Count
End Sub
Código fuente del formulario:
Private Sub btntodos1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntodos1.Click
Dim i As Integer
If lsttabla1.Items.Count > 0 Then 'Si no está en vacio la lista
'Recorremos el ListBox1
For i = 0 To lsttabla1.Items.Count - 1
lsttabla2.Items.Add(lsttabla1.Items(i))
Next
'Borramos la lista
lsttabla1.Items.Clear()
End If
'cuenta los valores de la lista
txttotal1.Text = lsttabla1.Items.Count
txttotal2.Text = lsttabla2.Items.Count
End Sub
Private Sub btnadd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd1.Click
lsttabla1.Items.Add(txtvalor1.Text)
txtvalor1.Clear()
txtvalor1.Focus()
'cuenta los valores de la lista
txttotal1.Text = lsttabla1.Items.Count
End Sub
Private Sub btnadd2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd2.Click
lsttabla2.Items.Add(txtvalor2.Text)
txtvalor2.Clear()
txtvalor2.Focus()
'cuenta los valores de la lista
txttotal2.Text = lsttabla2.Items.Count
End Sub
Private Sub btnuno1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuno1.Click
Dim valor As String
valor = lsttabla1.SelectedItem
lsttabla2.Items.Add(valor)
lsttabla1.Items.Remove(valor)
'cuenta los valores de la lista
txttotal2.Text = lsttabla2.Items.Count
txttotal1.Text = lsttabla1.Items.Count
End Sub
Private Sub btntodos2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntodos2.Click
Dim valor As String
valor = lsttabla2.SelectedItem
lsttabla1.Items.Add(valor)
lsttabla2.Items.Remove(valor)
'cuenta los valores de la lista
txttotal1.Text = lsttabla1.Items.Count
txttotal2.Text = lsttabla2.Items.Count
End Sub
Private Sub btnuno2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnuno2.Click
Dim i As Integer
If lsttabla2.Items.Count > 0 Then 'Si no está vacio la lista
'Recorremos el ListBox2
For i = 0 To lsttabla2.Items.Count - 1
lsttabla1.Items.Add(lsttabla2.Items(i))
Next
'Borramos la lista
lsttabla2.Items.Clear()
End If
'cuenta los valores de la lista
txttotal2.Text = lsttabla2.Items.Count
txttotal1.Text = lsttabla1.Items.Count
End Sub
Comentarios