How to display a property of a custom control with a dropdown styl

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default How to display a property of a custom control with a dropdown styl

    Hello,

    I have written my own custom control and I want one of its properties to
    display as a dropdown list when clicked, so the user can select from the
    list, it would be similar to the asp textbox control which has a ‘TextMode’
    property and when clicked on, displays as a dropdown list with 3 values, I
    want to have a similar type property with a dropdown style.

    So far, I have a property defined which displays the dropdown arrow when
    clicked but does not expand, I also do not know how to populate the dropdown.
    The dropdown needs to be populated with values read from the DB, the values
    can be read into a Dataset/datareader (which I can do), so I need to know how
    to bind these to a dropdown and have the dropdown assigned to the property.
    So far I have the following:

    1. My control

    Imports System
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.ComponentModel
    Imports System.Text
    Imports System.Drawing
    Imports UniversalDropdownEditor


    Namespace CustomAddressControl

    <DefaultProperty("Title"), ToolboxData("<{0}:Address
    runat=server></{0}:Address>")> _
    Public Class Address
    Inherits System.Web.UI.WebControls.WebControl

    Private iDataSource As String


    <Description("The source/origin of the data."), _
    Editor(GetType(EntryModeEditor), _
    GetType(System.Drawing.Design.UITypeEditor))> _
    Public Property DataSource() As String
    Get
    Return iDataSource
    End Get
    Set(ByVal Value As String)
    iDataSource = Value
    End Set
    End Property

    …………..

    2. My EntryModeEditor Class

    Imports System
    Imports System.ComponentModel
    Imports System.ComponentModel.Design
    Imports System.Drawing
    Imports System.Drawing.Design
    Imports System.Windows.Forms


    Imports System.Windows.Forms.Design
    <System.Security.Permissions.PermissionSetAttribut e(System.Security.Permissions.SecurityAction.Deman d, Name:="FullTrust")> _
    Public Class EntryModeEditor
    Inherits System.Drawing.Design.UITypeEditor

    Public Overloads Overrides Function EditValue(ByVal context As
    System.ComponentModel.ITypeDescriptorContext, ByVal provider As
    IServiceProvider, ByVal value As Object) As Object

    Dim returnValue As Object = value
    If Not (provider Is Nothing) Then

    ‘I DO NOT KNOW WHAT SHOULD GO IN HERE, TO POPULATE THE DROPDOWN AND GET OUT
    THE VALUE THAT WAS SELECTED

    End If
    Return value
    End Function


    Public Overloads Overrides Function GetEditStyle(ByVal context As _
    System.ComponentModel.ITypeDescriptorContext) As _
    System.Drawing.Design.UITypeEditorEditStyle
    If context Is Nothing Then
    Return MyBase.GetEditStyle(context)
    Else
    Return System.Drawing.Design.UITypeEditorEditStyle.DropDo wn
    End If

    End Function

    End Class

    Any help/suggestions would be gratefully appreciated.

    Thanks,
    Kay.

    Kay Guest

  2. Similar Questions and Discussions

    1. please help me with a Dropdown selectindexchange event into a custom control
      Hello, Im inserting a dropdownlist into a custom control, I fills it up, change the autopostback property to true, and finally assign the handler...
    2. Custom control with complex property type (System.Web.UI.Control[])
      I've built a control with a property of type System.Web.UI.Control. I have a custom editor which allows me to add items to this collection at...
    3. Keep custom property-value in custom rendered control
      Hi there, here's the thing I have a custom control (rendered) with a label, textbox and some validators. I use that for entering a birthdate, to...
    4. add events to dropdown list in custom server control
      Hi, It is easy to add an event to a hyperbutton, but what about a dropdownlist ? This is what I've implemented for the hyperbutton:...
    5. dropdown list in custom control not persiting databind
      testMy Custom Control doesn't has a drop down that pulls it's information from another class that I use to get generic here's the anotated version...
  3. #2

    Default Re: How to display a property of a custom control with a dropdown styl

    Hi,

    if the selection list is predefined e.g like TextMode is, just have it as
    enum type. It has the selection list applied automatically (quite simple)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    [url]http://blogs.aspadvice.com/joteke[/url]



    "Kay" <Kay@discussions.microsoft.com> wrote in message
    news:6666178E-7B9A-4EC5-B99C-8653B703BA66@microsoft.com...
    > Hello,
    >
    > I have written my own custom control and I want one of its properties to
    > display as a dropdown list when clicked, so the user can select from the
    > list, it would be similar to the asp textbox control which has a 'TextMode'
    > property and when clicked on, displays as a dropdown list with 3 values, I
    > want to have a similar type property with a dropdown style.
    >
    > So far, I have a property defined which displays the dropdown arrow when
    > clicked but does not expand, I also do not know how to populate the
    > dropdown.
    > The dropdown needs to be populated with values read from the DB, the
    > values
    > can be read into a Dataset/datareader (which I can do), so I need to know
    > how
    > to bind these to a dropdown and have the dropdown assigned to the
    > property.
    > So far I have the following:
    >
    > 1. My control
    >
    > Imports System
    > Imports System.Web.UI
    > Imports System.Web.UI.WebControls
    > Imports System.ComponentModel
    > Imports System.Text
    > Imports System.Drawing
    > Imports UniversalDropdownEditor
    >
    >
    > Namespace CustomAddressControl
    >
    > <DefaultProperty("Title"), ToolboxData("<{0}:Address
    > runat=server></{0}:Address>")> _
    > Public Class Address
    > Inherits System.Web.UI.WebControls.WebControl
    >
    > Private iDataSource As String
    >
    >
    > <Description("The source/origin of the data."), _
    > Editor(GetType(EntryModeEditor), _
    > GetType(System.Drawing.Design.UITypeEditor))> _
    > Public Property DataSource() As String
    > Get
    > Return iDataSource
    > End Get
    > Set(ByVal Value As String)
    > iDataSource = Value
    > End Set
    > End Property
    >
    > ......
    >
    > 2. My EntryModeEditor Class
    >
    > Imports System
    > Imports System.ComponentModel
    > Imports System.ComponentModel.Design
    > Imports System.Drawing
    > Imports System.Drawing.Design
    > Imports System.Windows.Forms
    >
    >
    > Imports System.Windows.Forms.Design
    > <System.Security.Permissions.PermissionSetAttribut e(System.Security.Permissions.SecurityAction.Deman d,
    > Name:="FullTrust")> _
    > Public Class EntryModeEditor
    > Inherits System.Drawing.Design.UITypeEditor
    >
    > Public Overloads Overrides Function EditValue(ByVal context As
    > System.ComponentModel.ITypeDescriptorContext, ByVal provider As
    > IServiceProvider, ByVal value As Object) As Object
    >
    > Dim returnValue As Object = value
    > If Not (provider Is Nothing) Then
    >
    > 'I DO NOT KNOW WHAT SHOULD GO IN HERE, TO POPULATE THE DROPDOWN AND GET
    > OUT
    > THE VALUE THAT WAS SELECTED
    >
    > End If
    > Return value
    > End Function
    >
    >
    > Public Overloads Overrides Function GetEditStyle(ByVal context As _
    > System.ComponentModel.ITypeDescriptorContext) As _
    > System.Drawing.Design.UITypeEditorEditStyle
    > If context Is Nothing Then
    > Return MyBase.GetEditStyle(context)
    > Else
    > Return System.Drawing.Design.UITypeEditorEditStyle.DropDo wn
    > End If
    >
    > End Function
    >
    > End Class
    >
    > Any help/suggestions would be gratefully appreciated.
    >
    > Thanks,
    > Kay.
    >

    Teemu Keiski Guest

  4. #3

    Default Re: How to display a property of a custom control with a dropdown styl

    And now I saw the db stuff. You can create a type converter

    [url]http://msdn2.microsoft.com/en-us/library/ayybcxe5.aspx[/url]


    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    [url]http://blogs.aspadvice.com/joteke[/url]

    "Kay" <Kay@discussions.microsoft.com> wrote in message
    news:6666178E-7B9A-4EC5-B99C-8653B703BA66@microsoft.com...
    > Hello,
    >
    > I have written my own custom control and I want one of its properties to
    > display as a dropdown list when clicked, so the user can select from the
    > list, it would be similar to the asp textbox control which has a 'TextMode'
    > property and when clicked on, displays as a dropdown list with 3 values, I
    > want to have a similar type property with a dropdown style.
    >
    > So far, I have a property defined which displays the dropdown arrow when
    > clicked but does not expand, I also do not know how to populate the
    > dropdown.
    > The dropdown needs to be populated with values read from the DB, the
    > values
    > can be read into a Dataset/datareader (which I can do), so I need to know
    > how
    > to bind these to a dropdown and have the dropdown assigned to the
    > property.
    > So far I have the following:
    >
    > 1. My control
    >
    > Imports System
    > Imports System.Web.UI
    > Imports System.Web.UI.WebControls
    > Imports System.ComponentModel
    > Imports System.Text
    > Imports System.Drawing
    > Imports UniversalDropdownEditor
    >
    >
    > Namespace CustomAddressControl
    >
    > <DefaultProperty("Title"), ToolboxData("<{0}:Address
    > runat=server></{0}:Address>")> _
    > Public Class Address
    > Inherits System.Web.UI.WebControls.WebControl
    >
    > Private iDataSource As String
    >
    >
    > <Description("The source/origin of the data."), _
    > Editor(GetType(EntryModeEditor), _
    > GetType(System.Drawing.Design.UITypeEditor))> _
    > Public Property DataSource() As String
    > Get
    > Return iDataSource
    > End Get
    > Set(ByVal Value As String)
    > iDataSource = Value
    > End Set
    > End Property
    >
    > ......
    >
    > 2. My EntryModeEditor Class
    >
    > Imports System
    > Imports System.ComponentModel
    > Imports System.ComponentModel.Design
    > Imports System.Drawing
    > Imports System.Drawing.Design
    > Imports System.Windows.Forms
    >
    >
    > Imports System.Windows.Forms.Design
    > <System.Security.Permissions.PermissionSetAttribut e(System.Security.Permissions.SecurityAction.Deman d,
    > Name:="FullTrust")> _
    > Public Class EntryModeEditor
    > Inherits System.Drawing.Design.UITypeEditor
    >
    > Public Overloads Overrides Function EditValue(ByVal context As
    > System.ComponentModel.ITypeDescriptorContext, ByVal provider As
    > IServiceProvider, ByVal value As Object) As Object
    >
    > Dim returnValue As Object = value
    > If Not (provider Is Nothing) Then
    >
    > 'I DO NOT KNOW WHAT SHOULD GO IN HERE, TO POPULATE THE DROPDOWN AND GET
    > OUT
    > THE VALUE THAT WAS SELECTED
    >
    > End If
    > Return value
    > End Function
    >
    >
    > Public Overloads Overrides Function GetEditStyle(ByVal context As _
    > System.ComponentModel.ITypeDescriptorContext) As _
    > System.Drawing.Design.UITypeEditorEditStyle
    > If context Is Nothing Then
    > Return MyBase.GetEditStyle(context)
    > Else
    > Return System.Drawing.Design.UITypeEditorEditStyle.DropDo wn
    > End If
    >
    > End Function
    >
    > End Class
    >
    > Any help/suggestions would be gratefully appreciated.
    >
    > Thanks,
    > Kay.
    >

    Teemu Keiski Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139