Please help with List2List control

L

lisa

I'm trying to create a List2List server control. I know there's a
sample out there by Guy Sofer, but I thought it could be a little
simpler.

When I drag the new control onto a WebForm, it shows up fine. But I
can't modify any properties of the child listboxes. Or rather, I can,
but it has no effect. If I add an item, say, to the Items collection
of one of the ListBoxes, it goes in just fine. But it doesn't show up
in Design view, and when I run the page, the item I added isn't there.
When I stop the page, it's gone in the design environment as well.

There's not a lot of code. And yes, I exposed the listboxes themselves
as mega-properties, but that seemed to work. At any rate, when I look
at the new control in design time, I seem to have access to all the
properties of each listbox. And I figured that the listboxes would
preserve their own viewstate without my needing to meddle.

Can someone please take a quick look at this and let me know what
stupid thing I'm doing wrong here?

Thanks,
Lisa

Option Strict On
Imports System
Imports System.ComponentModel
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO

<DefaultProperty("SelectedIndex"), Description("A List2List control
that uses ListBox"), ToolboxData("<{0}:pickList
runat=server></{0}:pickList>")> _
Public Class PickList
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer

Private _LeftList As New ListBox
Private _RightList As New ListBox
Private _MoveLeft As New Button
Private _MoveRight As New Button

Public Sub New()
CreateChildControls()
End Sub 'New

<Category("Child Controls"),
TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))>
_
Public Property RightList() As ListBox
Get
Me.EnsureChildControls()
Return _RightList
End Get
Set(ByVal Value As ListBox)
Me.EnsureChildControls()
_RightList = Value
End Set
End Property 'RightList

<Category("Child Controls"),
TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))>
_
Public Property LeftList() As ListBox
Get
Me.EnsureChildControls()
Return _LeftList
End Get
Set(ByVal Value As ListBox)
Me.EnsureChildControls()
_LeftList = Value
End Set
End Property 'LeftList

<Category("Child Controls"),
TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))>
_
Public Property MoveLeft() As Button
Get
Me.EnsureChildControls()
Return _MoveLeft
End Get
Set(ByVal Value As Button)
Me.EnsureChildControls()
_MoveLeft = Value
End Set
End Property 'MoveLeft

<Category("Child Controls"),
TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))>
_
Public Property MoveRight() As Button
Get
Me.EnsureChildControls()
Return _MoveRight
End Get
Set(ByVal Value As Button)
Me.EnsureChildControls()
_MoveRight = Value
End Set
End Property 'MoveRight

Protected Overrides Sub CreateChildControls()

_LeftList.ID = "LeftList"
_RightList.ID = "RightList"
_MoveLeft.ID = "MoveLeft"
_MoveRight.ID = "MoveRight"
_MoveLeft.Width = Unit.Pixel(25)
_MoveRight.Width = Unit.Pixel(25)
_MoveLeft.Font.Name = "wingdings"
_MoveRight.Font.Name = "wingdings"
_MoveLeft.Text = "×"
_MoveRight.Text = "Ø"

Controls.Clear()
Me.Controls.Add(New LiteralControl("<table cellspacing=0
cellpadding=0 style=display:inline><tr><td style=padding:0>"))
Me.Controls.Add(_LeftList)
Me.Controls.Add(New LiteralControl("</td><td valign=middle
style=padding:0>"))
Me.Controls.Add(_MoveLeft)
Me.Controls.Add(New LiteralControl("<p>"))
Me.Controls.Add(_MoveRight)
Me.Controls.Add(New LiteralControl("</td><td valign=middle
style=padding:0>"))
Me.Controls.Add(_RightList)
Me.Controls.Add(New LiteralControl("</td></tr></table>"))
End Sub 'CreateChildControls

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top