Mega Code Archive

 
Categories / VB.Net by API / System Windows Forms
 

ListBox Items RemoveAt

Imports System.Windows.Forms public class DualList    public Shared Sub Main         Application.Run(New Form1)    End Sub End class Public Class Form1     Private Sub btnAddSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSource.Click          lstSource.Items.Add("A")     End Sub     Private Sub btnAddDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDestination.Click          lstDestination.Items.Add("B")     End Sub     Private Sub btnClearSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearSource.Click         lstSource.Items.Clear()     End Sub     Private Sub btnClearDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearDestination.Click         lstDestination.Items.Clear()     End Sub     Private Sub btnRemoveSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveSource.Click         If lstSource.SelectedItems.Count > 0 Then             lstSource.Items.Remove(lstSource.SelectedItem)         End If     End Sub     Private Sub btnRemoveDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveDestination.Click         Dim intCounter As Integer         For intCounter = 0 To lstDestination.SelectedIndices.Count - 1             lstDestination.Items.RemoveAt(lstDestination.SelectedIndices(0))         Next intCounter     End Sub     Private Sub btnMoveDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveDestination.Click         If lstSource.SelectedItems.Count > 0 Then             lstDestination.Items.Add(lstSource.SelectedItem)             lstSource.Items.RemoveAt(lstSource.SelectedIndex)         End If     End Sub     Private Sub btnMoveSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveSource.Click         Dim intCounter As Integer         For intCounter = 0 To lstDestination.SelectedIndices.Count - 1             lstSource.Items.Add(lstDestination.Items(lstDestination.SelectedIndices(0)))             lstDestination.Items.Remove(lstDestination.Items(lstDestination.SelectedIndices(0)))         Next intCounter     End Sub     Private Sub btnMoveAllDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveAllDestination.Click         Dim intCounter As Integer         For intCounter = 0 To lstSource.Items.Count - 1             lstDestination.Items.Add(lstSource.Items(0))             lstSource.Items.RemoveAt(0)         Next intCounter     End Sub     Private Sub btnMoveAllSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveAllSource.Click         Dim intCounter As Integer         For intCounter = 0 To lstDestination.Items.Count - 1             lstSource.Items.Add(lstDestination.Items(0))             lstDestination.Items.RemoveAt(0)         Next intCounter     End Sub End Class Partial Public Class Form1     Inherits System.Windows.Forms.Form     <System.Diagnostics.DebuggerNonUserCode()> _     Public Sub New()         MyBase.New()         'This call is required by the Windows Form Designer.         InitializeComponent()     End Sub     'Form overrides dispose to clean up the component list.     <System.Diagnostics.DebuggerNonUserCode()> _     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)         If disposing AndAlso components IsNot Nothing Then             components.Dispose()         End If         MyBase.Dispose(disposing)     End Sub     'Required by the Windows Form Designer     Private components As System.ComponentModel.IContainer     'NOTE: The following procedure is required by the Windows Form Designer     'It can be modified using the Windows Form Designer.       'Do not modify it using the code editor.     <System.Diagnostics.DebuggerStepThrough()> _     Private Sub InitializeComponent()         Me.lstSource = New System.Windows.Forms.ListBox         Me.lstDestination = New System.Windows.Forms.ListBox         Me.btnMoveAllDestination = New System.Windows.Forms.Button         Me.btnMoveDestination = New System.Windows.Forms.Button         Me.btnMoveSource = New System.Windows.Forms.Button         Me.btnMoveAllSource = New System.Windows.Forms.Button         Me.btnAddSource = New System.Windows.Forms.Button         Me.btnRemoveSource = New System.Windows.Forms.Button         Me.btnClearSource = New System.Windows.Forms.Button         Me.btnAddDestination = New System.Windows.Forms.Button         Me.btnRemoveDestination = New System.Windows.Forms.Button         Me.btnClearDestination = New System.Windows.Forms.Button         Me.Label1 = New System.Windows.Forms.Label         Me.Label2 = New System.Windows.Forms.Label         Me.SuspendLayout()         '         'lstSource         '         Me.lstSource.FormattingEnabled = True         Me.lstSource.Location = New System.Drawing.Point(21, 25)         Me.lstSource.Name = "lstSource"         Me.lstSource.Size = New System.Drawing.Size(162, 199)         Me.lstSource.TabIndex = 0         '         'lstDestination         '         Me.lstDestination.FormattingEnabled = True         Me.lstDestination.Location = New System.Drawing.Point(254, 25)         Me.lstDestination.Name = "lstDestination"         Me.lstDestination.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended         Me.lstDestination.Size = New System.Drawing.Size(162, 199)         Me.lstDestination.Sorted = True         Me.lstDestination.TabIndex = 1         '         'btnMoveAllDestination         '         Me.btnMoveAllDestination.Location = New System.Drawing.Point(201, 48)         Me.btnMoveAllDestination.Name = "btnMoveAllDestination"         Me.btnMoveAllDestination.Size = New System.Drawing.Size(36, 28)         Me.btnMoveAllDestination.TabIndex = 2         Me.btnMoveAllDestination.Text = ">>"         '         'btnMoveDestination         '         Me.btnMoveDestination.Location = New System.Drawing.Point(201, 83)         Me.btnMoveDestination.Name = "btnMoveDestination"         Me.btnMoveDestination.Size = New System.Drawing.Size(36, 28)         Me.btnMoveDestination.TabIndex = 3         Me.btnMoveDestination.Text = ">"         '         'btnMoveSource         '         Me.btnMoveSource.Location = New System.Drawing.Point(201, 141)         Me.btnMoveSource.Name = "btnMoveSource"         Me.btnMoveSource.Size = New System.Drawing.Size(36, 28)         Me.btnMoveSource.TabIndex = 4         Me.btnMoveSource.Text = "<"         '         'btnMoveAllSource         '         Me.btnMoveAllSource.Location = New System.Drawing.Point(201, 176)         Me.btnMoveAllSource.Name = "btnMoveAllSource"         Me.btnMoveAllSource.Size = New System.Drawing.Size(36, 28)         Me.btnMoveAllSource.TabIndex = 5         Me.btnMoveAllSource.Text = "<<"         '         'btnAddSource         '         Me.btnAddSource.Location = New System.Drawing.Point(21, 237)         Me.btnAddSource.Name = "btnAddSource"         Me.btnAddSource.Size = New System.Drawing.Size(161, 24)         Me.btnAddSource.TabIndex = 6         Me.btnAddSource.Text = "Add Item"         '         'btnRemoveSource         '         Me.btnRemoveSource.Location = New System.Drawing.Point(22, 268)         Me.btnRemoveSource.Name = "btnRemoveSource"         Me.btnRemoveSource.Size = New System.Drawing.Size(161, 24)         Me.btnRemoveSource.TabIndex = 7         Me.btnRemoveSource.Text = "Remove Item"         '         'btnClearSource         '         Me.btnClearSource.Location = New System.Drawing.Point(22, 299)         Me.btnClearSource.Name = "btnClearSource"         Me.btnClearSource.Size = New System.Drawing.Size(161, 24)         Me.btnClearSource.TabIndex = 8         Me.btnClearSource.Text = "Clear Items"         '         'btnAddDestination         '         Me.btnAddDestination.Location = New System.Drawing.Point(254, 237)         Me.btnAddDestination.Name = "btnAddDestination"         Me.btnAddDestination.Size = New System.Drawing.Size(161, 24)         Me.btnAddDestination.TabIndex = 9         Me.btnAddDestination.Text = "Add Item"         '         'btnRemoveDestination         '         Me.btnRemoveDestination.Location = New System.Drawing.Point(254, 268)         Me.btnRemoveDestination.Name = "btnRemoveDestination"         Me.btnRemoveDestination.Size = New System.Drawing.Size(161, 24)         Me.btnRemoveDestination.TabIndex = 10         Me.btnRemoveDestination.Text = "Remove Item(s)"         '         'btnClearDestination         '         Me.btnClearDestination.Location = New System.Drawing.Point(254, 299)         Me.btnClearDestination.Name = "btnClearDestination"         Me.btnClearDestination.Size = New System.Drawing.Size(161, 24)         Me.btnClearDestination.TabIndex = 11         Me.btnClearDestination.Text = "Clear Items"         '         'Label1         '         Me.Label1.AutoSize = True         Me.Label1.Location = New System.Drawing.Point(20, 6)         Me.Label1.Name = "Label1"         Me.Label1.Size = New System.Drawing.Size(74, 14)         Me.Label1.TabIndex = 12         Me.Label1.Text = "Unsorted List:"         '         'Label2         '         Me.Label2.AutoSize = True         Me.Label2.Location = New System.Drawing.Point(254, 6)         Me.Label2.Name = "Label2"         Me.Label2.Size = New System.Drawing.Size(61, 14)         Me.Label2.TabIndex = 13         Me.Label2.Text = "Sorted List:"         '         'Form1         '         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)         Me.ClientSize = New System.Drawing.Size(438, 340)         Me.Controls.Add(Me.Label2)         Me.Controls.Add(Me.Label1)         Me.Controls.Add(Me.btnClearDestination)         Me.Controls.Add(Me.btnRemoveDestination)         Me.Controls.Add(Me.btnAddDestination)         Me.Controls.Add(Me.btnClearSource)         Me.Controls.Add(Me.btnRemoveSource)         Me.Controls.Add(Me.btnAddSource)         Me.Controls.Add(Me.btnMoveAllSource)         Me.Controls.Add(Me.btnMoveSource)         Me.Controls.Add(Me.btnMoveDestination)         Me.Controls.Add(Me.btnMoveAllDestination)         Me.Controls.Add(Me.lstDestination)         Me.Controls.Add(Me.lstSource)         Me.Name = "Form1"         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen         Me.Text = "ListDemo"         Me.ResumeLayout(False)         Me.PerformLayout()     End Sub     Friend WithEvents lstSource As System.Windows.Forms.ListBox     Friend WithEvents lstDestination As System.Windows.Forms.ListBox     Friend WithEvents btnMoveAllDestination As System.Windows.Forms.Button     Friend WithEvents btnMoveDestination As System.Windows.Forms.Button     Friend WithEvents btnMoveSource As System.Windows.Forms.Button     Friend WithEvents btnMoveAllSource As System.Windows.Forms.Button     Friend WithEvents btnAddSource As System.Windows.Forms.Button     Friend WithEvents btnRemoveSource As System.Windows.Forms.Button     Friend WithEvents btnClearSource As System.Windows.Forms.Button     Friend WithEvents btnAddDestination As System.Windows.Forms.Button     Friend WithEvents btnRemoveDestination As System.Windows.Forms.Button     Friend WithEvents btnClearDestination As System.Windows.Forms.Button     Friend WithEvents Label1 As System.Windows.Forms.Label     Friend WithEvents Label2 As System.Windows.Forms.Label End Class