Re: Collection of Collection control @ DESIGN TIME
- From: Nick WAELTI <nick@xxxxxxxxxx>
- Date: Wed, 04 May 2005 18:04:42 +0200
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 ?
Mujdat Dinc wrote:
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.
"Nick WAELTI" <nick@xxxxxxxxxx> wrote in message news:%23RqrGH%23TFHA.2128@xxxxxxxxxxxxxxxxxxxxxxx
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 ?
Mujdat Dinc wrote:
Nick,
I think your problem is about initilization of your properies.Next there
will be serialization problems.
Things to remember:
1. Dont forget to Initilizate the fields that the Properties points to in
your commpont InitializeComponent Functions.
2. Implement argumentless constructors for your classes. UIEditors uses
them.
3. Implement Correct Serialization Attributes
4. Implement Type converters for serialization of your clases if your class
is not derived from components.
"Nick WAELTI" <nick@xxxxxxxxxx> wrote in message news:ebHIgJ8TFHA.2712@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I'm building an extended treeview control starting from scratch. Works great so far, but I wanted to include some Rich Design Time features to it. This is what I have:
A treeview that has a property called Nodes Nodes is a collection that contains node A Node also has a property called Nodes
At design time, I can see my "Nodes" of the treeview in the propertygrid, when I click on [...] I get the basic collection editor which works great. When I click now on the [...] button of a Node.Nodes, I also get the collection editor, so far, so good.
But when I click OK on the Node.Nodes and then OK on the TreeView.Nodes collection editor, it tells me that "Object reference is not set to and instance of an object".
I've tried to implement some designer, some collection editor, some weird stuff, but I can't seem to go in the correct direction.
Does someone has some sample of code available or eventually some hints to point me in the correct direction ?
Thanks, Nick
.
- Follow-Ups:
- Re: Collection of Collection control @ DESIGN TIME
- From: Nick WAELTI
- Re: Collection of Collection control @ DESIGN TIME
- References:
- Collection of Collection control @ DESIGN TIME
- From: Nick WAELTI
- Re: Collection of Collection control @ DESIGN TIME
- From: Mujdat Dinc
- Re: Collection of Collection control @ DESIGN TIME
- From: Nick WAELTI
- Re: Collection of Collection control @ DESIGN TIME
- From: Mujdat Dinc
- Collection of Collection control @ DESIGN TIME
- Prev by Date: Re: how to inherit LinkLabel control
- Next by Date: ExpandableObjectConverter with no string representation
- Previous by thread: Re: Collection of Collection control @ DESIGN TIME
- Next by thread: Re: Collection of Collection control @ DESIGN TIME
- Index(es):
Relevant Pages
|