Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > create enumerated property for custom control

Reply
Thread Tools

create enumerated property for custom control

 
 
Sergey Poberezovskiy
Guest
Posts: n/a
 
      12-29-2005
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.


 
Reply With Quote
 
 
 
 
Mike MacMillan
Guest
Posts: n/a
 
      12-30-2005
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/de...classtopic.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.


 
Reply With Quote
 
 
 
 
Sergey Poberezovskiy
Guest
Posts: n/a
 
      12-30-2005
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/de...classtopic.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.

>
>

 
Reply With Quote
 
Mike MacMillan
Guest
Posts: n/a
 
      12-30-2005
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/de...classtopic.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.

> >
> >


 
Reply With Quote
 
Sergey Poberezovskiy
Guest
Posts: n/a
 
      12-30-2005
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/de...classtopic.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.
> > >
> > >

>
>

 
Reply With Quote
 
Mike MacMillan
Guest
Posts: n/a
 
      12-30-2005
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/de...classtopic.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.
> > > >
> > > >

> >
> >


 
Reply With Quote
 
Sergey Poberezovskiy
Guest
Posts: n/a
 
      12-30-2005
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.StandardValues Collection
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/de...classtopic.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.
> > > > >
> > > > >
> > >
> > >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enumerated type in a custom control tag Rex the Strange ASP .Net 3 07-25-2008 10:38 PM
create enumerated property for custom control Sergey Poberezovskiy ASP .Net Building Controls 0 11-07-2005 01:45 AM
Custom Control : One custom property to array of controls anon ASP .Net Web Controls 0 01-15-2005 11:32 AM
Keep custom property-value in custom rendered control Rob Joosen ASP .Net Building Controls 0 05-12-2004 11:56 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments
 



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