Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / May 2005

Tip: Looking for answers? Try searching our database.

Collection of Collection control @ DESIGN TIME

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick WAELTI - 03 May 2005 10:27 GMT
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
   
Mujdat Dinc - 03 May 2005 12:11 GMT
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.

> Hi,
>
[quoted text clipped - 23 lines]
> Thanks,
> Nick
Nick WAELTI - 03 May 2005 14:12 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.