VB.NET Two List box value add and remove


CODE :
Public Class Form1

    Private Sub btnadd1to2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd1to2.Click
        Dim i As Integer
        For i = 0 To ListBox1.SelectedItems.Count - 1
            ListBox2.Items.Add(ListBox1.SelectedItems.Item(0))
            ListBox1.Items.Remove(ListBox1.SelectedItem)
        Next
        Call valid()
    End Sub
    Private Sub btnadd2to1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd2to1.Click
        Dim i As Integer
        For i = 0 To ListBox2.SelectedItems.Count - 1
            ListBox1.Items.Add(ListBox2.SelectedItems.Item(0))
            ListBox2.Items.Remove(ListBox2.SelectedItem)
        Next
        Call valid()
    End Sub
    Private Sub btnaddall1to2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddall1to2.Click
        For i = 0 To ListBox1.Items.Count - 1
            ListBox2.Items.Add(ListBox1.Items.Item(i))
        Next
        ListBox1.Items.Clear()
        Call valid()
    End Sub

    Private Sub btnaddall2to1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddall2to1.Click
        For i = 0 To ListBox2.Items.Count - 1
            ListBox1.Items.Add(ListBox2.Items.Item(i))
        Next
        ListBox2.Items.Clear()
        Call valid()
    End Sub
    Private Sub valid()
        If ListBox1.Items.Count < 1 Then
            btnadd1to2.Enabled = False
            btnaddall1to2.Enabled = False
        Else
            btnadd1to2.Enabled = True
            btnaddall1to2.Enabled = True
        End If
        If ListBox2.Items.Count < 1 Then
            btnadd2to1.Enabled = False
            btnaddall2to1.Enabled = False
        Else
            btnadd2to1.Enabled = True
            btnaddall2to1.Enabled = True
        End If
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call valid()
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        If txtitem.Text.Trim <> "" Then
            ListBox1.Items.Add(txtitem.Text)
            txtitem.Clear()
            txtitem.Focus()
        End If
        Call valid()
    End Sub

    Private Sub txtitem_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtitem.TextChanged
        If txtitem.Text.Trim.Length > 0 Then
            btnadd.Enabled = True
        Else
            btnadd.Enabled = False
        End If
    End Sub
End Class


VB.NET Two List box value add and remove VB.NET Two List box value add and remove Reviewed by Unknown on 12:05 pm Rating: 5

No comments: