Public Partial Class SelectorBox
Inherits System.Web.UI.UserControl
Private objChoices As System.Web.UI.WebControls.ListItemCollection
Private objSelected As System.Web.UI.WebControls.ListItemCollection
Private strTheSelectedValues As string
Private intHeight As integer = 400
Private intWidth As integer = 200

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If not objChoices is Nothing then
      For Each selItem In objChoices
        lstChoices.Items.Add(selItem)
      Next
    End If
    If not objSelected is Nothing then
      For Each selItem In objSelected
        lstSelected.Items.Add(selItem)
      Next
    End If
    lstChoices.Height = HeightOfBox
    'divMiddlebox.Style.Item("Height") = HeightOfBox
    lstSelected.Height = HeightOfBox 
    lstChoices.Width = WidthOfBox 
    lstSelected.Width = WidthOfBox
  End Sub
  Public Sub btnAdd_Click()
    For intCount = lstChoices.Items.Count - 1 to 0 step -1
  		dim selItem as System.Web.UI.WebControls.ListItem
      selItem = lstChoices.Items(intCount)
        Dim li = lstChoices.Items.FindByValue(selItem.Value)
        If li.Selected = True then
          lstSelected.Items.Add(li)
          lstChoices.Items.Remove(li)
        end if
    Next intCount
    For Each selItem In lstSelected.Items
      selItem.Selected = False
    Next
    lstChoices.ClearSelection
  End Sub
  Public Sub btnDel_Click()
    For intCount = lstSelected.Items.Count - 1 to 0 step -1
  		dim selItem as System.Web.UI.WebControls.ListItem
      selItem = lstSelected.Items(intCount)
        Dim li = lstSelected.Items.FindByValue(selItem.Value)
        If li.Selected = True then
          lstChoices.Items.Add(li)
          lstSelected.Items.Remove(li)
        end if
    Next intCount
    For Each selItem In lstChoices.Items
      selItem.Selected = False
    Next
    lstSelected.ClearSelection
  End Sub
#Region "Public properties"
  Public Property TheChoices() As System.Web.UI.WebControls.ListItemCollection
      Get
          Return objChoices 
      End Get
      Set(ByVal value As System.Web.UI.WebControls.ListItemCollection)
          objChoices = value
      End Set
  End Property
  Public Property TheSelected() As System.Web.UI.WebControls.ListItemCollection 
      Get
        Dim objListCollection As new System.Web.UI.WebControls.ListItemCollection
        dim selItem as System.Web.UI.WebControls.ListItem
        For Each selItem in lstSelected.Items
          objListCollection.Add(selItem)
        Next
        Return objListCollection  
      End Get
      Set(ByVal value As System.Web.UI.WebControls.ListItemCollection)
          objSelected = value
      End Set
  End Property
  Public Property TheSelectedValuesCSV() As string
      Get
        Dim strOutput As String = ""
        For Each selItem In TheSelected
          ' Save it items stored in the the Selected listbox
          strOutput += selItem.Value & chr(167)
        ' Chr(167) is the double S symbol
        Next 
        If Right(strOutput, 1) = Chr(167) then
          strOutput = Left(strOutput, (Len(strOutput) - 1))
        End If
      Return strOutput
      End Get
      Set(ByVal value As string)
          strTheSelectedValues = value
      End Set
  End Property
  Public Property HeightOfBox() As String
    Get
        Return intHeight 
    End Get
    Set(ByVal value As String)
        intHeight = value
    End Set
  End Property
  Public Property WidthOfBox() As String
      Get
          Return intWidth 
      End Get
      Set(ByVal value As String)
          intWidth = value
      End Set
  End Property
#End Region
End Class