H
Hazim
I am designing a component to be used on windows applications.
'code''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class SomeComponent
Inherits System.ComponentModel.Component
Private _gaugeSettings As New GaugeConfiguration
Public Property GaugeSettings() As GaugeConfiguration
....
end property
End Class
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I want user to be able to configure the GaugeSettings within the
Development environment.
'code''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<TypeConverter(GetType(GaugeConfigurationConvertor)), _
DescriptionAttribute("Expand to see the GaugeSettings.")> _
Public Class GaugeConfiguration
......
End Class
Public Class GaugeConfigurationConvertor
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
If destinationType Is GetType(GaugeConfiguration) Then
Return True
End If
Return MyBase.CanConvertFrom(context, destinationType)
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
If (destinationType Is GetType(System.String) AndAlso TypeOf
value Is GaugeConfiguration) Then
Dim gaugeSettings As GaugeConfiguration = CType(value,
GaugeConfiguration)
Return "string representation of the class"
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object) As Object
If (TypeOf value Is String) Then
Try
Dim gaugeSettings As New GaugeConfiguration
.....
Return gaugeSettings
Catch
Throw New ArgumentException("Can not convert '" &
CStr(value) & "' to GaugeConfiguration")
End Try
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
End Class
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When I try to configure this SomeComponent object on a form, things work
fine until I try to save the form, when I try to save, I get the
following error;
Code generation for property 'GaugeSettings' failed. Error was:
''GaugeConfigurationConvertor' is unable to convert
'LaserGaugeControl.GaugeConfiguration' to
'System.ComponentModel.Design.Serialization.InstanceDescriptor'.'
I actually added Serialization support to GaugeSettings class and a
clone method, still I kept getting the same error.
Can anyone help?
Thanks a lot,
Hazim...
'code''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class SomeComponent
Inherits System.ComponentModel.Component
Private _gaugeSettings As New GaugeConfiguration
Public Property GaugeSettings() As GaugeConfiguration
....
end property
End Class
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I want user to be able to configure the GaugeSettings within the
Development environment.
'code''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<TypeConverter(GetType(GaugeConfigurationConvertor)), _
DescriptionAttribute("Expand to see the GaugeSettings.")> _
Public Class GaugeConfiguration
......
End Class
Public Class GaugeConfigurationConvertor
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
If destinationType Is GetType(GaugeConfiguration) Then
Return True
End If
Return MyBase.CanConvertFrom(context, destinationType)
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
If (destinationType Is GetType(System.String) AndAlso TypeOf
value Is GaugeConfiguration) Then
Dim gaugeSettings As GaugeConfiguration = CType(value,
GaugeConfiguration)
Return "string representation of the class"
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object) As Object
If (TypeOf value Is String) Then
Try
Dim gaugeSettings As New GaugeConfiguration
.....
Return gaugeSettings
Catch
Throw New ArgumentException("Can not convert '" &
CStr(value) & "' to GaugeConfiguration")
End Try
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
End Class
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
When I try to configure this SomeComponent object on a form, things work
fine until I try to save the form, when I try to save, I get the
following error;
Code generation for property 'GaugeSettings' failed. Error was:
''GaugeConfigurationConvertor' is unable to convert
'LaserGaugeControl.GaugeConfiguration' to
'System.ComponentModel.Design.Serialization.InstanceDescriptor'.'
I actually added Serialization support to GaugeSettings class and a
clone method, still I kept getting the same error.
Can anyone help?
Thanks a lot,
Hazim...