Customdesigner

R

Rich Hackett

Hi, I'm trying to write a web control which is basically a calendar
control(need to add extra functionality later)

I have the first phase working eg a calendar control is rendered and
works as expected but because I inherit webcontrol not Calendar I
don't get the properties for it in the VS designer.

I found several articles on this around using the prefilterproperties
function but I am struggling to get this to work.

here's the code
Protected Overrides Sub PreFilterProperties(ByVal properties As
System.Collections.IDictionary)
Dim props As PropertyDescriptorCollection
MyBase.PreFilterProperties(properties)
props = TypeDescriptor.GetProperties(GetType(Calendar))
Dim propitem As PropertyDescriptor
Dim runtimeAttributes As
System.componentmodel.AttributeCollection
Dim attrs() As Attribute
For Each propitem In props
runtimeAttributes = propitem.Attributes
ReDim attrs(runtimeAttributes.Count - 1)
runtimeAttributes.CopyTo(attrs, 0)
properties(propitem.Name) =
TypeDescriptor.CreateProperty(GetType(Calendar), propitem.Name, attrs)
Next
It works fine for all the properties which are common eg backcolor,
font ... but not for the custom calendar properties
DayHeaderStyle,TitleFormat.. all return "Object reference not set to
an instance of an object." in the property window. There are also
some properties which don't appear against the normal Calendar
properties presumeably these are hidden. Any ideas?
 
J

John Saunders

Rich Hackett said:
Hi, I'm trying to write a web control which is basically a calendar
control(need to add extra functionality later)

I have the first phase working eg a calendar control is rendered and
works as expected but because I inherit webcontrol not Calendar I
don't get the properties for it in the VS designer.

I found several articles on this around using the prefilterproperties
function but I am struggling to get this to work.

here's the code
Protected Overrides Sub PreFilterProperties(ByVal properties As
System.Collections.IDictionary)
Dim props As PropertyDescriptorCollection
MyBase.PreFilterProperties(properties)
props = TypeDescriptor.GetProperties(GetType(Calendar))
Dim propitem As PropertyDescriptor
Dim runtimeAttributes As
System.componentmodel.AttributeCollection
Dim attrs() As Attribute
For Each propitem In props
runtimeAttributes = propitem.Attributes
ReDim attrs(runtimeAttributes.Count - 1)
runtimeAttributes.CopyTo(attrs, 0)
properties(propitem.Name) =
TypeDescriptor.CreateProperty(GetType(Calendar), propitem.Name, attrs)
Next
It works fine for all the properties which are common eg backcolor,
font ... but not for the custom calendar properties
DayHeaderStyle,TitleFormat.. all return "Object reference not set to
an instance of an object." in the property window. There are also
some properties which don't appear against the normal Calendar
properties presumeably these are hidden. Any ideas?

Rich, was there some reason you couldn't just inherit from the calendar
control?
 
R

Rich Hackett

Rich, was there some reason you couldn't just inherit from the calendar
The end to end dream is that the developer can drag a control onto the
page and by default it will show a text box and a show calendar icon.
When the calendar is displayed it will have a drop down for month and
for year to enable quick navigation. There will also be a close
button so you don't have to pick a date. I managed to get most of
this working from the inheritence but obviously the calendar doesn't
have a child collection so I could only add the new elements in the
render procedure. This lead to me not being able to wire up events
correctly as it is after the page_load event. So I inherited the
webcontrol class and publically defined calendar and the linkbutton.

I also wanted to add extra properties to the calendar like show close
link show navigation boxes
 
J

John Saunders

Rich Hackett said:
The end to end dream is that the developer can drag a control onto the
page and by default it will show a text box and a show calendar icon.
When the calendar is displayed it will have a drop down for month and
for year to enable quick navigation. There will also be a close
button so you don't have to pick a date. I managed to get most of
this working from the inheritence but obviously the calendar doesn't
have a child collection so I could only add the new elements in the
render procedure.

I don't know what you mean. Why can't you add the elements in
CreateChildControls?
This lead to me not being able to wire up events
correctly as it is after the page_load event. So I inherited the
webcontrol class and publically defined calendar and the linkbutton.

I also wanted to add extra properties to the calendar like show close
link show navigation boxes

This should not be a problem if you use inheritance.
 
R

Rich Hackett

John Saunders said:
I don't know what you mean. Why can't you add the elements in
CreateChildControls?


This should not be a problem if you use inheritance.

If you use the createchildcontrols you'd need to either use me or
mybase.controls.add This is not allowed as "the collection object is
nothing" Therefore cannot add any controls to the calendar control.
You cannot add it to the page as you will get "cannot edit parents
controls" message.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top