Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Expandable properties in propertygrid not working

Reply
Thread Tools

Expandable properties in propertygrid not working

 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-24-2003
I am trying to create expandable properties in the propertygrid for a custom
control i am building but it wont work. I have derived my TypeConverter
from ExpandableObjectoConverter. I have overridden :
CanConvertFrom,ConvertFrom,ConvertTo,CanConvertTo. I know exactly what these
do. I have read the docs thoroughly and properly implemented it all. Still
the properties thats supposed to be expandable arent for some reason. I have
been struggling with this for a few hours now. To simplify this i have
created a small test application with my implementation. Can anybody give it
a look and let me know where i went wrong and what i should be doing
instead.
Thanks


Imports System.ComponentModel
Imports System.ComponentModel.Design.Serialization
Imports System.Web.UI

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

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")> Property
[Text]() As String
Get
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.Write([Text])
End Sub

End Class
<TypeConverter(GetType(ExpandablePropertiesTypeCon verter)),
Category("Appearance"), _
DescriptionAttribute("Two expandable properties")> _
Public Class ExpandableProperties
Private _sampleValue1 As Boolean = True
Private _sampleValue2 As Boolean = True
<DefaultValueAttribute(True), _
Description("Expandable property 2")> _
Public Property [sampleValue1]() As Boolean
Get
Return _sampleValue1
End Get

Set(ByVal Value As Boolean)
_sampleValue1 = Value
End Set
End Property

<DefaultValueAttribute(True), _
Description("Expandable property 2")> _
Public Property [sampleValue2]() As Boolean
Get
Return _sampleValue2
End Get

Set(ByVal Value As Boolean)
_sampleValue2 = Value
End Set
End Property
End Class


------------ Then in a seperate file i got the type converter class:
ExpandablePropertiesTypeConverter.vb ----------------------------

Imports System.ComponentModel
Imports System.Globalization
Public Class ExpandablePropertiesTypeConverter : Inherits
ExpandableObjectConverter
' Overrides the CanConvertFrom method of TypeConverter.
Public Overloads Overrides Function CanConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
If sourceType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
' Overrides the ConvertFrom method of TypeConverter.
Public Overloads Overrides Function ConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object)
As Object
If (TypeOf value Is String) Then
Try
Dim s As String = CStr(value)
Dim colon As Integer = s.IndexOf(":")
Dim comma As Integer = s.IndexOf(",")

If (colon <> -1 AndAlso comma <> -1) Then
Dim samplevalue1 As String = s.Substring(colon + 1, _
(comma - colon - 1))

colon = s.IndexOf(":", comma + 1)
comma = s.IndexOf(",", comma + 1)

Dim samplevalue2 As String = s.Substring(colon + 1, _
(comma - colon - 1))

Dim control1 As ExpandableProperties = New
ExpandableProperties()

control1.sampleValue1 = Boolean.Parse(samplevalue1)
control1.sampleValue2 = Boolean.Parse(samplevalue2)

Return control1
End If
Catch
Throw New ArgumentException( _
"Can not convert '" & CStr(value) & _
"' to type windowAttributes")

End Try
End If
Return MyBase.ConvertFrom(context, culture, value)

End Function

' Overrides the ConvertTo method of TypeConverter.
Public Overloads Overrides Function ConvertTo(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object,
ByVal destinationType As Type) As Object
If (destinationType Is GetType(System.String) _
AndAlso TypeOf value Is ExpandableProperties) Then

Dim control1 As ExpandableProperties = CType(value,
ExpandableProperties)
Return "Sample1:" & control1.sampleValue1 & ", Sample2:" &
control1.sampleValue2
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function

Public Overloads Overrides Function CanConvertTo( _
ByVal context As ITypeDescriptorContext, _
ByVal destinationType As Type) As Boolean
If (destinationType Is GetType(ExpandableProperties)) Then
Return True
End If
Return MyBase.CanConvertFrom(context, destinationType)
End Function
End Class


 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-24-2003
Just in case nobody is looking at this thinking I want someone to make
corrections to my code, this is not the case. The reason I put sample code
is to show that I have followed whatever documentation microsoft had on
expandable properties and its not working for me. Has anybody dealt with
this before. That is when trying to implement expandable properties and it
dont work. I dont end up with errors either, those properties never show in
the propertygrid. Not as expandable properties or the normal expanded
properties. Just nada.

"Alessandro Zifiglio" <(E-Mail Removed)> wrote in message
news:RTccb.427$(E-Mail Removed)...
> I am trying to create expandable properties in the propertygrid for a

custom
> control i am building but it wont work. I have derived my TypeConverter
> from ExpandableObjectoConverter. I have overridden :
> CanConvertFrom,ConvertFrom,ConvertTo,CanConvertTo. I know exactly what

these
> do. I have read the docs thoroughly and properly implemented it all. Still
> the properties thats supposed to be expandable arent for some reason. I

have
> been struggling with this for a few hours now. To simplify this i have
> created a small test application with my implementation. Can anybody give

it
> a look and let me know where i went wrong and what i should be doing
> instead.
> Thanks
>
>
> Imports System.ComponentModel
> Imports System.ComponentModel.Design.Serialization
> Imports System.Web.UI
>
> <DefaultProperty("Text"), _
> ToolboxData("<{0}:WebCustomControl1

runat=server></{0}:WebCustomControl1>")>
> _
> Public Class WebCustomControl1
> Inherits System.Web.UI.WebControls.WebControl
>
> Dim _text As String
>
> <Bindable(True), Category("Appearance"), DefaultValue("")> Property
> [Text]() As String
> Get
> Return _text
> End Get
>
> Set(ByVal Value As String)
> _text = Value
> End Set
> End Property
>
> Protected Overrides Sub Render(ByVal output As
> System.Web.UI.HtmlTextWriter)
> output.Write([Text])
> End Sub
>
> End Class
> <TypeConverter(GetType(ExpandablePropertiesTypeCon verter)),
> Category("Appearance"), _
> DescriptionAttribute("Two expandable properties")> _
> Public Class ExpandableProperties
> Private _sampleValue1 As Boolean = True
> Private _sampleValue2 As Boolean = True
> <DefaultValueAttribute(True), _
> Description("Expandable property 2")> _
> Public Property [sampleValue1]() As Boolean
> Get
> Return _sampleValue1
> End Get
>
> Set(ByVal Value As Boolean)
> _sampleValue1 = Value
> End Set
> End Property
>
> <DefaultValueAttribute(True), _
> Description("Expandable property 2")> _
> Public Property [sampleValue2]() As Boolean
> Get
> Return _sampleValue2
> End Get
>
> Set(ByVal Value As Boolean)
> _sampleValue2 = Value
> End Set
> End Property
> End Class
>
>
> ------------ Then in a seperate file i got the type converter class:
> ExpandablePropertiesTypeConverter.vb ----------------------------
>
> Imports System.ComponentModel
> Imports System.Globalization
> Public Class ExpandablePropertiesTypeConverter : Inherits
> ExpandableObjectConverter
> ' Overrides the CanConvertFrom method of TypeConverter.
> Public Overloads Overrides Function CanConvertFrom(ByVal context As
> ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
> If sourceType Is GetType(String) Then
> Return True
> End If
> Return MyBase.CanConvertFrom(context, sourceType)
> End Function
> ' Overrides the ConvertFrom method of TypeConverter.
> Public Overloads Overrides Function ConvertFrom(ByVal context As
> ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As

Object)
> As Object
> If (TypeOf value Is String) Then
> Try
> Dim s As String = CStr(value)
> Dim colon As Integer = s.IndexOf(":")
> Dim comma As Integer = s.IndexOf(",")
>
> If (colon <> -1 AndAlso comma <> -1) Then
> Dim samplevalue1 As String = s.Substring(colon + 1, _
> (comma - colon -

1))
>
> colon = s.IndexOf(":", comma + 1)
> comma = s.IndexOf(",", comma + 1)
>
> Dim samplevalue2 As String = s.Substring(colon + 1, _
> (comma - colon -

1))
>
> Dim control1 As ExpandableProperties = New
> ExpandableProperties()
>
> control1.sampleValue1 = Boolean.Parse(samplevalue1)
> control1.sampleValue2 = Boolean.Parse(samplevalue2)
>
> Return control1
> End If
> Catch
> Throw New ArgumentException( _
> "Can not convert '" & CStr(value) & _
> "' to type windowAttributes")
>
> End Try
> End If
> Return MyBase.ConvertFrom(context, culture, value)
>
> End Function
>
> ' Overrides the ConvertTo method of TypeConverter.
> Public Overloads Overrides Function ConvertTo(ByVal context As
> ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As

Object,
> ByVal destinationType As Type) As Object
> If (destinationType Is GetType(System.String) _
> AndAlso TypeOf value Is ExpandableProperties) Then
>
> Dim control1 As ExpandableProperties = CType(value,
> ExpandableProperties)
> Return "Sample1:" & control1.sampleValue1 & ", Sample2:" &
> control1.sampleValue2
> End If
> Return MyBase.ConvertTo(context, culture, value, destinationType)
> End Function
>
> Public Overloads Overrides Function CanConvertTo( _
> ByVal context As ITypeDescriptorContext,

_
> ByVal destinationType As Type) As

Boolean
> If (destinationType Is GetType(ExpandableProperties)) Then
> Return True
> End If
> Return MyBase.CanConvertFrom(context, destinationType)
> End Function
> End Class
>
>



 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-25-2003
Will somebody from Microsoft reply. It is important that I be able to
implement expandable properties. If I've been doing it right then maybe
someone knows of a workaround I could use to get this running for me? For
all I can think of right now is that this could be a bug with the vb.net
version.
I'm already behind schedule. I am desperate.
Microsoft !!!



 
Reply With Quote
 
Jimmy [Used-Disks]
Guest
Posts: n/a
 
      09-25-2003
> Public Class WebCustomControl1

Where do you declare the property?

Also, though a TypeConverter may be useful, it looks like
ExpandableObjectConverter will do just fine in your case. There is no need
to extend it from what I can see.

--
-Jimmy
Used-Disks:
http://www.used-disks.com/


 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-25-2003
Why am i being ignored. I see the guys from microsoft responding but wont
aknowledge my post.

It cant be so hard to reproduce my problem. I even included a sample project
to simplify. Still no answer


 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-25-2003
Its all there in my sample code. I have to extend it. I need to extend. I
want to overridable properties of the the expandableobjectconverter.
Otherwise my properties wont be editable and i cant use a custom display as
items are selected in the sub properties.
However I had already tried doing it simply as you suggested before posting
for the sake of experimenting and even that didnt wont work for me.
Have you been able to implement expandable properties in vb.net and has it
worked for you?
For all i can think of right now, this is a bug. I'm using the older version
of the framework because my version of VS.NET is the 2002 version and it
wont work with ASP.net 1.1

I'm not sure if my problem is a bug and has already been fixed with the
latest release of the the framework 1.1 version, if this is so i'd like the
confirmation and what i need to do to get this working with my current
version of the framework and not have to upgrade because that would mean my
purchasing vs.net 2003.

"Jimmy [Used-Disks]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > Public Class WebCustomControl1

>
> Where do you declare the property?
>
> Also, though a TypeConverter may be useful, it looks like
> ExpandableObjectConverter will do just fine in your case. There is no need
> to extend it from what I can see.
>
> --
> -Jimmy
> Used-Disks:
> http://www.used-disks.com/
>
>




 
Reply With Quote
 
Ben Schwehn
Guest
Posts: n/a
 
      09-25-2003
On Wed, 24 Sep 2003 10:43:59 +0200, Alessandro Zifiglio wrote:

> I am trying to create expandable properties in the propertygrid for a custom
> control i am building but it wont work.


Allessandro,

perhaps this is stupid, and you seem stressed so don't get angry if it is
indeed stupid, but don't you have to use the
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)
attribute thing as well?
never done a converter but just a simple expandable property and that needed
this attribute to work...

hth
ben


 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-25-2003
hi ben,
The DesignerSerializationVisibility attribute class is useful in cases you
want to serialize the contents of your read/write property value.
However I'll do anything right now to get this working and tried adding that
attribute anyway. It didnt change a thing for me.
Thanks for trying to help, i appreciate it.

If only someone from microsoft would confirm this to be a bug in their
vb.net version and put me on the right track.


"Ben Schwehn" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Wed, 24 Sep 2003 10:43:59 +0200, Alessandro Zifiglio wrote:
>
> > I am trying to create expandable properties in the propertygrid for a

custom
> > control i am building but it wont work.

>
> Allessandro,
>
> perhaps this is stupid, and you seem stressed so don't get angry if it is
> indeed stupid, but don't you have to use the
> DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)
> attribute thing as well?
> never done a converter but just a simple expandable property and that

needed
> this attribute to work...
>
> hth
> ben
>
>




 
Reply With Quote
 
Ben Schwehn
Guest
Posts: n/a
 
      09-26-2003
Hello Allessandro,

I had a look at your sample code and if I use

Dim _test As ExpandableProperties
<Bindable(True), Category("Appearance"), DefaultValue("")> Property Test() As ExpandableProperties
Get
Return _test
End Get
Set(ByVal Value As ExpandableProperties)
_test = Value
End Set
End Property

in your websustomcontrol1

and change your convertfrom to

Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
If (TypeOf value Is String) Then
Try

Dim control1 As ExpandableProperties = New ExpandableProperties()
control1.sampleValue1 = True
control1.sampleValue2 = False

Return control1


Catch
Throw New ArgumentException( _
"Can not convert '" & CStr(value) & _
"' to type windowAttributes")

End Try
End If
Return MyBase.ConvertFrom(context, culture, value)

End Function

then the test property is displayed in the property grid as not expandable
firtst (because its not inititlised?) but
if you enter a string it uses the ConvertFrom function to set sampleValue1
to true etc and the Property is afterwards displayed as expandable

There seem to be some problems with you convertfrom function eg confusing
colon with komma at one point, perhaps there are more...

I'd first fix that and then perhaps initialise the test property

hth
ben

 
Reply With Quote
 
Ben Schwehn
Guest
Posts: n/a
 
      09-26-2003
> Hello Allessandro,
^^

and apologies for misspelling your name - again
 
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
Changing DisplayNames of my properties using PropertyGrid component, how ?? Tugrul HELVACI ASP .Net 3 12-05-2006 03:04 AM
PropertyGrid-Need HELP =?Utf-8?B?RGVlcGFr?= ASP .Net 2 07-15-2005 08:40 AM
Expandable Properties in DataBinding Dialog -j via .NET 247 ASP .Net Building Controls 0 06-15-2004 08:35 PM
PropertyGrid - ReadOnly Dave Wurtz ASP .Net 2 11-14-2003 04:55 PM
Expandable properties in propertygrid not working Alessandro Zifiglio ASP .Net Web Controls 7 10-07-2003 09:03 PM



Advertisments