create enumerated property for custom control

Discussion in 'ASP .Net Building Controls' started by Sergey Poberezovskiy, Dec 29, 2005.

  1. Hi,

    I want to create a property that can only accept values from my custom list.
    Say
    1, 5, 10, 15, 20, 30.

    I know I can easily create an enumeration with values set to those from my
    list, and have the Visual Studio designer display a list of enumerated
    strings shown in the property (e.g. one, five, ten, etc.).

    What I want is a list of numbers shown in the IDE - and I have no idea how to
    do that...

    Any help is greatly appreciated.
     
    Sergey Poberezovskiy, Dec 29, 2005
    #1
    1. Advertising

  2. Sergey,
    any custom information you'd like displayed by the IDE is design mode
    is up to you to implement. take a look at the ControlDesigner class
    and its associated members, as that will give you a headstart for
    providing custom design-time support for your controls. here's a link
    to the SDK:


    http://msdn.microsoft.com/library/d...ystemwebuidesigncontroldesignerclasstopic.asp

    hope this helps,
    Mike MacMillan

    Sergey Poberezovskiy wrote:
    > Hi,
    >
    > I want to create a property that can only accept values from my custom list.
    > Say
    > 1, 5, 10, 15, 20, 30.
    >
    > I know I can easily create an enumeration with values set to those from my
    > list, and have the Visual Studio designer display a list of enumerated
    > strings shown in the property (e.g. one, five, ten, etc.).
    >
    > What I want is a list of numbers shown in the IDE - and I have no idea how to
    > do that...
    >
    > Any help is greatly appreciated.
     
    Mike MacMillan, Dec 30, 2005
    #2
    1. Advertising

  3. Mike,

    I was not asking about the DesignTimeHtml - I know how to use that...
    The question was about how to implement a property similar to say,
    BorderStyle, so that when user selects the property in the Properties window
    the valid values are listed in the dropdown box.

    Hope that makes sense..

    "Mike MacMillan" wrote:

    > Sergey,
    > any custom information you'd like displayed by the IDE is design mode
    > is up to you to implement. take a look at the ControlDesigner class
    > and its associated members, as that will give you a headstart for
    > providing custom design-time support for your controls. here's a link
    > to the SDK:
    >
    >
    > http://msdn.microsoft.com/library/d...ystemwebuidesigncontroldesignerclasstopic.asp
    >
    > hope this helps,
    > Mike MacMillan
    >
    > Sergey Poberezovskiy wrote:
    > > Hi,
    > >
    > > I want to create a property that can only accept values from my custom list.
    > > Say
    > > 1, 5, 10, 15, 20, 30.
    > >
    > > I know I can easily create an enumeration with values set to those from my
    > > list, and have the Visual Studio designer display a list of enumerated
    > > strings shown in the property (e.g. one, five, ten, etc.).
    > >
    > > What I want is a list of numbers shown in the IDE - and I have no idea how to
    > > do that...
    > >
    > > Any help is greatly appreciated.

    >
    >
     
    Sergey Poberezovskiy, Dec 30, 2005
    #3
  4. Sergey,
    any properties who's type are an enum will be bound to that list of
    values in design mode. if you view properties of the control/class
    who's property you'd like to edit, if one is an enum, VS will display a
    dropdownlist with the values from the enum as a list of available
    choices.

    Mike MacMillan


    Sergey Poberezovskiy wrote:
    > Mike,
    >
    > I was not asking about the DesignTimeHtml - I know how to use that...
    > The question was about how to implement a property similar to say,
    > BorderStyle, so that when user selects the property in the Properties window
    > the valid values are listed in the dropdown box.
    >
    > Hope that makes sense..
    >
    > "Mike MacMillan" wrote:
    >
    > > Sergey,
    > > any custom information you'd like displayed by the IDE is design mode
    > > is up to you to implement. take a look at the ControlDesigner class
    > > and its associated members, as that will give you a headstart for
    > > providing custom design-time support for your controls. here's a link
    > > to the SDK:
    > >
    > >
    > > http://msdn.microsoft.com/library/d...ystemwebuidesigncontroldesignerclasstopic.asp
    > >
    > > hope this helps,
    > > Mike MacMillan
    > >
    > > Sergey Poberezovskiy wrote:
    > > > Hi,
    > > >
    > > > I want to create a property that can only accept values from my custom list.
    > > > Say
    > > > 1, 5, 10, 15, 20, 30.
    > > >
    > > > I know I can easily create an enumeration with values set to those from my
    > > > list, and have the Visual Studio designer display a list of enumerated
    > > > strings shown in the property (e.g. one, five, ten, etc.).
    > > >
    > > > What I want is a list of numbers shown in the IDE - and I have no idea how to
    > > > do that...
    > > >
    > > > Any help is greatly appreciated.

    > >
    > >
     
    Mike MacMillan, Dec 30, 2005
    #4
  5. Mike,

    As you could see from the very first post the type of property is integer
    (1, 5, 10...)
    I have no problem restricting the user to enter those values only by raising
    an error in the property set block. My goal is that the user can select one
    of the valid values in the dropdown.

    The property I am trying to implement is the minute interval on TimePicker
    control - it makes sense to make it of an integer (byte) type.

    Any ideas?

    "Mike MacMillan" wrote:

    > Sergey,
    > any properties who's type are an enum will be bound to that list of
    > values in design mode. if you view properties of the control/class
    > who's property you'd like to edit, if one is an enum, VS will display a
    > dropdownlist with the values from the enum as a list of available
    > choices.
    >
    > Mike MacMillan
    >
    >
    > Sergey Poberezovskiy wrote:
    > > Mike,
    > >
    > > I was not asking about the DesignTimeHtml - I know how to use that...
    > > The question was about how to implement a property similar to say,
    > > BorderStyle, so that when user selects the property in the Properties window
    > > the valid values are listed in the dropdown box.
    > >
    > > Hope that makes sense..
    > >
    > > "Mike MacMillan" wrote:
    > >
    > > > Sergey,
    > > > any custom information you'd like displayed by the IDE is design mode
    > > > is up to you to implement. take a look at the ControlDesigner class
    > > > and its associated members, as that will give you a headstart for
    > > > providing custom design-time support for your controls. here's a link
    > > > to the SDK:
    > > >
    > > >
    > > > http://msdn.microsoft.com/library/d...ystemwebuidesigncontroldesignerclasstopic.asp
    > > >
    > > > hope this helps,
    > > > Mike MacMillan
    > > >
    > > > Sergey Poberezovskiy wrote:
    > > > > Hi,
    > > > >
    > > > > I want to create a property that can only accept values from my custom list.
    > > > > Say
    > > > > 1, 5, 10, 15, 20, 30.
    > > > >
    > > > > I know I can easily create an enumeration with values set to those from my
    > > > > list, and have the Visual Studio designer display a list of enumerated
    > > > > strings shown in the property (e.g. one, five, ten, etc.).
    > > > >
    > > > > What I want is a list of numbers shown in the IDE - and I have no idea how to
    > > > > do that...
    > > > >
    > > > > Any help is greatly appreciated.
    > > >
    > > >

    >
    >
     
    Sergey Poberezovskiy, Dec 30, 2005
    #5
  6. Sergey,
    perhaps you can define an enumeration (as you said in the first
    post), then replace the direct int property assignment with the enum.
    this would restrict the user's selection in design time(and in general)
    to only the values defined in the enum. then, in the set accessor of
    the enum's property, you can set an internal int value that represents
    the actual int value of the selected enum member. this would pretty
    much do as you requested, unless i misunderstand (please let me know).

    hope this helps,
    Mike MacMillan


    Sergey Poberezovskiy wrote:
    > Mike,
    >
    > As you could see from the very first post the type of property is integer
    > (1, 5, 10...)
    > I have no problem restricting the user to enter those values only by raising
    > an error in the property set block. My goal is that the user can select one
    > of the valid values in the dropdown.
    >
    > The property I am trying to implement is the minute interval on TimePicker
    > control - it makes sense to make it of an integer (byte) type.
    >
    > Any ideas?
    >
    > "Mike MacMillan" wrote:
    >
    > > Sergey,
    > > any properties who's type are an enum will be bound to that list of
    > > values in design mode. if you view properties of the control/class
    > > who's property you'd like to edit, if one is an enum, VS will display a
    > > dropdownlist with the values from the enum as a list of available
    > > choices.
    > >
    > > Mike MacMillan
    > >
    > >
    > > Sergey Poberezovskiy wrote:
    > > > Mike,
    > > >
    > > > I was not asking about the DesignTimeHtml - I know how to use that...
    > > > The question was about how to implement a property similar to say,
    > > > BorderStyle, so that when user selects the property in the Properties window
    > > > the valid values are listed in the dropdown box.
    > > >
    > > > Hope that makes sense..
    > > >
    > > > "Mike MacMillan" wrote:
    > > >
    > > > > Sergey,
    > > > > any custom information you'd like displayed by the IDE is design mode
    > > > > is up to you to implement. take a look at the ControlDesigner class
    > > > > and its associated members, as that will give you a headstart for
    > > > > providing custom design-time support for your controls. here's a link
    > > > > to the SDK:
    > > > >
    > > > >
    > > > > http://msdn.microsoft.com/library/d...ystemwebuidesigncontroldesignerclasstopic.asp
    > > > >
    > > > > hope this helps,
    > > > > Mike MacMillan
    > > > >
    > > > > Sergey Poberezovskiy wrote:
    > > > > > Hi,
    > > > > >
    > > > > > I want to create a property that can only accept values from my custom list.
    > > > > > Say
    > > > > > 1, 5, 10, 15, 20, 30.
    > > > > >
    > > > > > I know I can easily create an enumeration with values set to those from my
    > > > > > list, and have the Visual Studio designer display a list of enumerated
    > > > > > strings shown in the property (e.g. one, five, ten, etc.).
    > > > > >
    > > > > > What I want is a list of numbers shown in the IDE - and I have no idea how to
    > > > > > do that...
    > > > > >
    > > > > > Any help is greatly appreciated.
    > > > >
    > > > >

    > >
    > >
     
    Mike MacMillan, Dec 30, 2005
    #6
  7. Mike,

    While I was trying to reason an answer to you that your proposed solution is
    not exactly that I wanted, I worked out the way to do it:

    1. Define a converter class, say
    2. Set property attributes

    The code follows:

    1.

    Public Class ShortConverter
    Inherits Int16Converter

    Public Shared defaultEnum As StandardValuesCollection

    Public Overloads Overrides Function GetStandardValuesSupported(ByVal
    context As System.ComponentModel.ITypeDescriptorContext) As Boolean
    Return True
    End Function

    Public Overloads Overrides Function GetStandardValuesExclusive(ByVal
    context As System.ComponentModel.ITypeDescriptorContext) As Boolean
    Return True
    End Function

    Public Overloads Overrides Function GetStandardValues(ByVal context As
    System.ComponentModel.ITypeDescriptorContext) As
    System.ComponentModel.TypeConverter.StandardValuesCollection
    Return defaultEnum
    End Function
    End Class

    2. in the control class:

    Private Const _DEF_MINUTES_INTERVAL As Short = 1
    Private Shared _intervals() As Short = {_DEF_MINUTES_INTERVAL, 5, 10, 15,
    20, 30}

    <TypeConverter(GetType(ShortConverter)), _
    Description("Specifies minutes intervals."), _
    DefaultValue(_DEF_MINUTES_INTERVAL)> _
    Public Property MinutesInterval() As Short
    Get
    If Me.Context Is Nothing Then
    ShortConverter.defaultEnum = New
    TypeConverter.StandardValuesCollection(_intervals)
    End If
    Return Common.GetInt16Property(Me.ViewState, "MinutesInterval",
    _DEF_MINUTES_INTERVAL)
    End Get
    Set(ByVal Value As Short)
    If Array.IndexOf(_intervals, Value) > -1 Then
    Common.SetInt16Property(Me.ViewState, "MinutesInterval", Value,
    _DEF_MINUTES_INTERVAL)
    End If
    End Set
    End Property

    Hope that may help someone else...


    "Mike MacMillan" wrote:

    > Sergey,
    > perhaps you can define an enumeration (as you said in the first
    > post), then replace the direct int property assignment with the enum.
    > this would restrict the user's selection in design time(and in general)
    > to only the values defined in the enum. then, in the set accessor of
    > the enum's property, you can set an internal int value that represents
    > the actual int value of the selected enum member. this would pretty
    > much do as you requested, unless i misunderstand (please let me know).
    >
    > hope this helps,
    > Mike MacMillan
    >
    >
    > Sergey Poberezovskiy wrote:
    > > Mike,
    > >
    > > As you could see from the very first post the type of property is integer
    > > (1, 5, 10...)
    > > I have no problem restricting the user to enter those values only by raising
    > > an error in the property set block. My goal is that the user can select one
    > > of the valid values in the dropdown.
    > >
    > > The property I am trying to implement is the minute interval on TimePicker
    > > control - it makes sense to make it of an integer (byte) type.
    > >
    > > Any ideas?
    > >
    > > "Mike MacMillan" wrote:
    > >
    > > > Sergey,
    > > > any properties who's type are an enum will be bound to that list of
    > > > values in design mode. if you view properties of the control/class
    > > > who's property you'd like to edit, if one is an enum, VS will display a
    > > > dropdownlist with the values from the enum as a list of available
    > > > choices.
    > > >
    > > > Mike MacMillan
    > > >
    > > >
    > > > Sergey Poberezovskiy wrote:
    > > > > Mike,
    > > > >
    > > > > I was not asking about the DesignTimeHtml - I know how to use that...
    > > > > The question was about how to implement a property similar to say,
    > > > > BorderStyle, so that when user selects the property in the Properties window
    > > > > the valid values are listed in the dropdown box.
    > > > >
    > > > > Hope that makes sense..
    > > > >
    > > > > "Mike MacMillan" wrote:
    > > > >
    > > > > > Sergey,
    > > > > > any custom information you'd like displayed by the IDE is design mode
    > > > > > is up to you to implement. take a look at the ControlDesigner class
    > > > > > and its associated members, as that will give you a headstart for
    > > > > > providing custom design-time support for your controls. here's a link
    > > > > > to the SDK:
    > > > > >
    > > > > >
    > > > > > http://msdn.microsoft.com/library/d...ystemwebuidesigncontroldesignerclasstopic.asp
    > > > > >
    > > > > > hope this helps,
    > > > > > Mike MacMillan
    > > > > >
    > > > > > Sergey Poberezovskiy wrote:
    > > > > > > Hi,
    > > > > > >
    > > > > > > I want to create a property that can only accept values from my custom list.
    > > > > > > Say
    > > > > > > 1, 5, 10, 15, 20, 30.
    > > > > > >
    > > > > > > I know I can easily create an enumeration with values set to those from my
    > > > > > > list, and have the Visual Studio designer display a list of enumerated
    > > > > > > strings shown in the property (e.g. one, five, ten, etc.).
    > > > > > >
    > > > > > > What I want is a list of numbers shown in the IDE - and I have no idea how to
    > > > > > > do that...
    > > > > > >
    > > > > > > Any help is greatly appreciated.
    > > > > >
    > > > > >
    > > >
    > > >

    >
    >
     
    Sergey Poberezovskiy, Dec 30, 2005
    #7
    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. Rex the Strange

    Enumerated type in a custom control tag

    Rex the Strange, Jul 25, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    501
    Rex the Strange
    Jul 25, 2008
  2. Matt Sokol
    Replies:
    2
    Views:
    437
    Theo Tillotson
    Aug 7, 2003
  3. Rob Joosen

    Keep custom property-value in custom rendered control

    Rob Joosen, May 12, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    159
    Rob Joosen
    May 12, 2004
  4. Sergey Poberezovskiy

    create enumerated property for custom control

    Sergey Poberezovskiy, Nov 7, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    132
    Sergey Poberezovskiy
    Nov 7, 2005
  5. anon
    Replies:
    0
    Views:
    221
Loading...

Share This Page