Please help with List2List control

Discussion in 'ASP .Net Web Controls' started by lisa@starways.net, Apr 5, 2005.

  1. Guest

    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
    , Apr 5, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    490
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    516
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,717
    Mike Hewson
    Jan 7, 2005
  4. mera
    Replies:
    7
    Views:
    1,078
  5. Problem with a List2List control

    , Apr 6, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    122
Loading...

Share This Page