468,270 Members | 1,544 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,270 developers. It's quick & easy.

Help - User control and serialization

Tom
I am having a really annoying issue with serialization and a .NET User
Control I am writing. For example, let's say I have a couple of classes in
my control - first class is like:

Public Class User
Private _UserName As String
Private _UserCity As String
<System.ComponentModel.CategoryAttribute("User Info")> _
Public Property UserName() As String
Get
Return _UserName
End Get
Set(ByVal Value As String)
_UserName = Value
End Set
End Property
<System.ComponentModel.CategoryAttribute("User Info")> _
Public Property UserCity() As String
Get
Return _UserCity
End Get
Set(ByVal Value As String)
_UserCity = Value
End Set
End Property
End Class

Then the second class is a collection of the first, as so:

<Serializable()> _
Public Class UserCollection
Inherits Collections.CollectionBase

Default Public Property Item(ByVal index As Integer) As User
Get
Return CType(List(index), User)
End Get
Set(ByVal Value As User)
List(index) = Value
End Set
End Property

Public Function Add(ByVal value As User) As Integer
Return List.Add(value)
End Function
...
... (more functions follow, such as IndexOf, etc)
...
End Class

Then, in my .NET User Control, I have the following:

Private _UserFields As New UserCollection()
<System.ComponentModel.DesignerSerializationVisibi lity(ComponentModel.Design
erSerializationVisibility.Content), _
System.ComponentModel.Description("User Information"), _
System.ComponentModel.CategoryAttribute("User Info")> _
Public ReadOnly Property UserCriteria() As UserCollection
Get
Return _UserFields
End Get
End Property

In the solution I also have a test project that uses the control (just so I
can test it).

This seems to work fine as long as I am in the designer; i.e. I can use the
property pages to add user collection data (i.e. Name, City). I can close
Visual Studio and reopen the solution; the items I added are still there.
However, if I go to run the solution (by clicking on the run icon or
selecting Debug-Start or pressing F5) I end up with the following errors:

1. The test form that is hosting the control (form1.vb) goes white in the
designer and shows the following error message:

"An error occured while loading the document. Fix the error, and then try
loading the document again. The error message follows: The designer cannot
be modified at this time."

This occurs even though the form seems to execute fine and the application
shows up on the screen. I close the application and go back to the VB.NET
IDE, then close and reopen form1.vb in the designer (to get rid of the white
screen). Then the following build error shows up:

2. "At least one element in the source array could not be cast down to the
destination array type."

3. And then, when I use the property page and look at my control collection,
NOTHING is there anymore (i.e. the items I added before are all gone).

I have found VERY FEW articles or examples on making a control and using a
collection classe for property pages; the one I did find basically came up
with the same errors. It is very probable that I am missing something or
not doing something right (maybe I need to read the serialized data or
something when I actually execute the program??) But I am at a loss at this
point. If I can't figure this out I will just have to allow runtime only
modification of my control, which is something I really don't want to do.

Anyone know what I am missing here? Or know of a good example of this being
done in a user control? Thanks in advance....

Tom
Nov 20 '05 #1
0 1843

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jeff T. | last post: by
23 posts views Thread by Jason | last post: by
8 posts views Thread by Martin Horn | last post: by
1 post views Thread by Christo | last post: by
1 post views Thread by Mihai Velicu | last post: by
4 posts views Thread by Mihai | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.