Hi,
Thanks for your answer. May be you can clarify some stuff:
What do you mean by "initialize the fields that the properties ..."
I do have argumentless constructors
I've implemented the "<Serializable()>" attribute, isn't that enough ?
I've a type converter for my "Node" but not for the "Collection". Would
I need one for the collection as well ?
This is my typeconverter (declared for the node class like that:
<TypeConverter(GetType(TreeListNodeConverter)),
DesignTimeVisible(False), ToolboxItem(False), Serializable()> _
Public Class TreeListNode
Inherits Component
######################################################################
Friend Class TreeListNodeConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
Try
If sourceType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
Catch ex As Exception
MsgBox("CanConvertFrom:" & ex.Message)
End Try
End Function
Public Overloads Overrides Function CanConvertTo(ByVal context As
ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
Try
If destinationType Is GetType(InstanceDescriptor) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
Catch ex As Exception
MsgBox("CanConvertTo:" & ex.Message)
End Try
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object, ByVal destinationType As Type) As Object
Try
If destinationType Is GetType(InstanceDescriptor) Then
Dim ci As System.Reflection.ConstructorInfo =
GetType(TreeListNode).GetConstructor(System.Type.EmptyTypes)
Return New InstanceDescriptor(ci, Nothing, True)
End If
Return MyBase.ConvertTo(context, culture, value,
destinationType)
Catch ex As Exception
MsgBox("ConvertTo:" & ex.Message)
End Try
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As
ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As
Object) As Object
Try
If TypeOf value Is String Then
Return value
End If
Return MyBase.ConvertFrom(context, culture, value)
Catch ex As Exception
MsgBox("ConvertFrom:" & ex.Message)
End Try
End Function
End Class
######################################################################
Basically, the way my thing works is as follow:
TREELIST
- Inherits from Control
- No special attributes
Properties:
- Nodes (as New) (TREELISTNODECOLLECTION)
TREELISTNODECOLLECTION
- Inherits from CollectionBase
- Attr. DesignTimeVisible(False)
- Attr. ToolboxItem(False)
- Attr. Serializable()
Properties:
- Item (ReadOnly) (TREELISTNODE)
TREELISTNODE
- Inherits from Component
- Attr. TypeConverter(TreeListNodeConverter) (see above)
- Attr. Serializable()
- Attr. DesignTimeVisible(False)
- Attr. ToolboxItem(False)
Properties:
- Nodes (as New) (TREELISTNODECOLLECTION)
I have also tried to use a specific designer for the TreeList but... no
success.
Do you see where I could have a problem ?
> Nick,
> I think your problem is about initilization of your properies.Next there
[quoted text clipped - 35 lines]
>>Thanks,
>>Nick
Mujdat Dinc - 04 May 2005 10:16 GMT
Hi,
I ll write samples in C# .
class Node
{
.....
NodesColllection _nodes;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public NodesColllection Nodes
{
get
{
return _notes;
}
set
{
_notes= value;
}
}
//Above _notes field is not initialized, its null
// Make _nodes = new NodesColllection(); in initialize rutin
// Check all the properties and ensure all are initialized with in all
constuctors called.
// Initialize in a common function and call that function in each
constructor.
..........
}
* Serializable Attribute is not a design time attibute.. Here the
serialization is designtime Serialization. It s for designer hosts (Visial
studio) renders your designed properties to Code. To make your serialize
correcly this attributes is important. Use
DesignerSerializationVisibilityAttibute to effet how to serialize the
component. Use DesignerSerializationVisibility.Content when you use
collections. Read MSND for more help.
* Your nodes class derived from Component, so you dont need to use Type
converter for InstanceDescriptor. If its not ,then must use to Type
converter for InstanceDescriptor to intilizate your class. (Example Point
Class)
*If your you colection calls is typed collection (Collection opretions uses
the type Node) Then there is no need for type converts.
> Hi,
>
[quoted text clipped - 144 lines]
>>>Thanks,
>>>Nick
Nick WAELTI - 04 May 2005 17:04 GMT
Thanks for your answer, I've checked everything, but that still won't do
the trick.
_Nodes is initialized, I've the argument
DesignerSerializationVisibility.Content but...
Does not work. Any other idea ?
> Hi,
> I ll write samples in C# .
[quoted text clipped - 185 lines]
>>>>Thanks,
>>>>Nick
Nick WAELTI - 04 May 2005 18:20 GMT
Nevermind, I managed to do it using an UITypeEditor that references
itself...
> Thanks for your answer, I've checked everything, but that still won't do
> the trick.
[quoted text clipped - 195 lines]
>>>>> Thanks,
>>>>> Nick