T
Todd Lucas via .NET 247
I'm having some weird things happen in design view while editinga custom collection - I've been at this for about 4 weeks now,and have tried all the different combinations of persistencesettings (DesignerSerializationVisibility, PersistenceMode, etc)there is, and all to no avail! I'm hoping someone here can help...
Environment: VS.NET 2003 v7.1.3088, Win2000 v5.00.2195 SP3, IE6v6.0.2800.1106CO
The problem is one of collection item persistence. The problemcan be repeated by using the following steps:
1) create new webform, and drop C3Menu control on it fromToolbox.
2) click control to select it.
3) click ellipse button on the MenuItems property to editcollection (via standard CollectionEditor).
4) add a new item, and click Ok button to save changes / closecollection editor.
5) switch to HTML view - changes are persisted ok.
6) switch back to design view, and run the test project.
7) control appears fine on webform, with all items listed.
8) close webform to return to design view.
9) click control to select it.
10) click ellipse button on the MenuItems property to editcollection (via standard CollectionEditor).
11) add a new item, and click Ok button to save changes / closecollection editor.
12) switch to HTML view - changes are NOT persisted!
It gets even weirder, because if I repeat steps 9-12 a secondtime (right after doing all 12) to add another new item, theprevious item AND the second new item are persisted!
If I remove the "SET" accessor on the MenuItems property in theC3Menu class, a new problem is presented: "Design View: Errorcreating control - '' could not be set on property MenuItems". This problem occurs if I close the webform after adding items tothe collection, and try to reopen it. The application stillruns ok, and the control is presented properly on the webform atrun time, but the designer complains that the control cannot becreated (above message) - I then cannot access any propertiesfor the control in design view, but can add new items in theHTML view and they appear fine on the webform at run time.
Any ideas? I would be happy to send the full source code toanyone that wants to help. Any help would be appreciated.
The Code (snippets):
Environment: VS.NET 2003 v7.1.3088, Win2000 v5.00.2195 SP3, IE6v6.0.2800.1106CO
The problem is one of collection item persistence. The problemcan be repeated by using the following steps:
1) create new webform, and drop C3Menu control on it fromToolbox.
2) click control to select it.
3) click ellipse button on the MenuItems property to editcollection (via standard CollectionEditor).
4) add a new item, and click Ok button to save changes / closecollection editor.
5) switch to HTML view - changes are persisted ok.
6) switch back to design view, and run the test project.
7) control appears fine on webform, with all items listed.
8) close webform to return to design view.
9) click control to select it.
10) click ellipse button on the MenuItems property to editcollection (via standard CollectionEditor).
11) add a new item, and click Ok button to save changes / closecollection editor.
12) switch to HTML view - changes are NOT persisted!
It gets even weirder, because if I repeat steps 9-12 a secondtime (right after doing all 12) to add another new item, theprevious item AND the second new item are persisted!
If I remove the "SET" accessor on the MenuItems property in theC3Menu class, a new problem is presented: "Design View: Errorcreating control - '' could not be set on property MenuItems". This problem occurs if I close the webform after adding items tothe collection, and try to reopen it. The application stillruns ok, and the control is presented properly on the webform atrun time, but the designer complains that the control cannot becreated (above message) - I then cannot access any propertiesfor the control in design view, but can add new items in theHTML view and they appear fine on the webform at run time.
Any ideas? I would be happy to send the full source code toanyone that wants to help. Any help would be appreciated.
The Code (snippets):
Code:
C3Menu Class:
<DefaultEvent("ItemClick"), _
Description("Server Control - Menu Definition."), _
ParseChildren(True, "MenuItems"), PersistChildren(False), _
ToolboxData("<{0}:C3Menu runat=server></{0}:C3Menu>")> _
Public Class C3Menu : InheritsSystem.Web.UI.WebControls.WebControl
...
Dim _menuitems As New C3MenuItemCollection
...
<Category("Menu Properties"), NotifyParentProperty(True), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerDefaultProperty), _
Description("Collection of Menu Items this object willdisplay.")> _
ReadOnly Property [MenuItems]() As C3MenuItemCollection
Get
Return _menuitems
End Get
'SET causes control creation errors when the page is loaded!
'Set(ByVal Value As C3MenuItemCollection)
' If Not IsNothing(Value) Then _menuitems = Value
'End Set
End Property
...
C3MenuItemCollection Class:
Public Class C3MenuItemCollection
Inherits System.Collections.CollectionBase
Public Sub New()
MyBase.New()
End Sub
Default Public Property Item(ByVal index As Integer) AsC3MenuItem
Get
Return CType(Me.List(index), C3MenuItem)
End Get
Set(ByVal Value As C3MenuItem)
Me.List(index) = Value
End Set
End Property
Public Function Add(ByVal value As C3MenuItem) AsInteger
Return Me.List.Add(value)
End Function
Public Function Contains(ByVal value As C3MenuItem) AsBoolean
Return Me.List.Contains(value)
End Function
Public Function IndexOf(ByVal value As C3MenuItem) AsInteger
Return Me.List.IndexOf(value)
End Function
Public Sub Remove(ByVal value As C3MenuItem)
Me.List.Remove(value)
End Sub
Public Sub Insert(ByVal index As Integer, ByVal value AsC3MenuItem)
Me.List.Insert(index, value)
End Sub
End Class
C3MenuItem Class:
(All properties in this class are one of the following types: String, Boolean, Color)
Public Class C3MenuItem
Public pOwningMenu As C3Menu
' MenuItem property storage:
Dim _align As String = ""
Dim _closeonclick As Boolean = True
Dim _color3dlow As Color = ColorTranslator.FromHtml("")
...