You are on page 1of 3

TALLER - GUIA USO DE LIXTBOXT

De acuerdo a lo visto en clase se debe desarrollar este taller con el objeto de analizar y entender como es el manejo de controles de Visual Basic.Net.

Public Class Form1 Private Const msgbox_Eliminar As String = "Para eliminar un dato, debe seleccionarlo previamente" Private Const msgbox_Pasar_Dato As String = "Para pasar un dato, debe seleccionarlo previamente" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With ListBox1 .Items.Add("Footbal") .Items.Add("Tenis") .Items.Add("Baloncesto") .Items.Add("Rana") .Items.Add("Tejo") .Items.Add("Natacin") .Items.Add("Atletismo") End With Label1.Text = ListBox1.Items.Count & " elemento(s)" End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'Aadir ListBox1 If TextBox1.Text <> "" Then ListBox1.Items.Add(TextBox1.Text) Label1.Text = ListBox1.Items.Count & " elemento(s)" TextBox1.Text = "" End If

End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click 'Eliminar ListBox1 If ListBox1.SelectedIndex <> -1 Then 'Si hay datos seleccionados en el control, 'eliminamos el dato seleccionado ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) Label1.Text = ListBox1.Items.Count & " elemento(s)" Else MessageBox.Show(msgbox_Eliminar, msgbox_Title, MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Pasa todos los elementos del control ListBox1 al control ListBox2 While ListBox1.Items.Count > 0 ListBox1.SelectedIndex = ListBox1.Items.Count - 1 ListBox2.Items.Add(ListBox1.SelectedItem) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) End While Label1.Text = ListBox1.Items.Count & " elemento(s)" Label2.Text = ListBox2.Items.Count & " elemento(s)" End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click ListBox2.Sorted = True ListBox2.Sorted = False End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Pasa todos los elementos del control ListBox2 al control ListBox1 While ListBox2.Items.Count > 0 ListBox2.SelectedIndex = ListBox2.Items.Count - 1 ListBox1.Items.Add(ListBox2.SelectedItem) ListBox2.Items.RemoveAt(ListBox2.SelectedIndex) End While Label1.Text = ListBox1.Items.Count & " elemento(s)" Label2.Text = ListBox2.Items.Count & " elemento(s)" End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'Pasa un dato seleccionado del control ListBox1 al control ListBox2 If ListBox1.SelectedIndex <> -1 Then 'Si hay datos seleccionados en el control, 'pasamos el dato seleccionado ListBox2.Items.Add(ListBox1.SelectedItem) ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) Label1.Text = ListBox1.Items.Count & " elemento(s)" Label2.Text = ListBox2.Items.Count & " elemento(s)" Else If ListBox1.Items.Count > 0 Then MessageBox.Show(msgbox_Pasar_Dato, msgbox_Title, MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

'Pasa un dato seleccionado del control ListBox2 al control ListBox1 If ListBox2.SelectedIndex <> -1 Then 'Si hay datos seleccionados en el control, 'pasamos el dato seleccionado ListBox1.Items.Add(ListBox2.SelectedItem) ListBox2.Items.RemoveAt(ListBox2.SelectedIndex) Label1.Text = ListBox1.Items.Count & " elemento(s)" Label2.Text = ListBox2.Items.Count & " elemento(s)" Else If ListBox2.Items.Count > 0 Then MessageBox.Show(msgbox_Pasar_Dato, msgbox_Title, MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If End Sub End Class

You might also like