Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Collection property "could not be initialized" in design mode for custom datagrid control

Reply
Thread Tools

Collection property "could not be initialized" in design mode for custom datagrid control

 
 
BluegrassNate
Guest
Posts: n/a
 
      12-07-2005
Hello all,

I've been working on a custom datagrid (custom web control inherited
from DataGrid). I am attempting to add a new collection property to
the control as described all over this group and the web... seems like
it should be easy but I've been at it for about a week

Here's the problem: I am able to use my custom collection editor to add
collection items just fine, but the collection refuses to 'rebuild'
itself when I reopen the aspx file and gives the very helpful error
''NonDraggableColumns' could not be initialized". Obviously
NonDraggableColumns is my collection property.

Here are some relevant fragments:

ASPX code for datagrid looks like this:

<cc1:dhtmldatagrid id="dgResults" runat="server"
AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:BoundColumn DataField="test" HeaderText="test"></asp:BoundColumn>
</Columns>
<NonDraggableColumns>
<cc1ataGridColumnIndex ParentPosition="0"></cc1ataGridColumnIndex>
</NonDraggableColumns>
</cc1:dhtmldatagrid>

So the editor did its job and correctly added an item to my custom
collection, which is simply a collection of DataGridColumnIndex objects
inherited from CollectionBase. I've provided the proper indexers and
Add methods, etc.

The DataGridColumnIndex class is very very simple (because I just need
to get a collection like this working first!) and only has one public
property - ParentPosition (Int32).

My collection property is defined in my control as follows:

[Editor(typeof(ACS.Bluegrass.Web.Controls.ColumnCol lectionSubsetEditor),
typeof(System.Drawing.Design.UITypeEditor)),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)]
public DataGridColumnCollectionSubset NonDraggableColumns
{
get
{
if (nonDraggableColumns == null)
{
nonDraggableColumns = new DataGridColumnCollectionSubset();
}

return nonDraggableColumns;
}
}

Of course, the control class is marked as ParseChildren(true),
PersistChildren(false).

Everything has the same namespace. The strangest thing is, if I simply
use and ArrayList instead of my CollectionBase -based collection class,
the parsing will suceed, BUT only if I manually remove the namespace
prefix (cc1 from the inner <cc1ataGridColumnIndex
ParentPosition="0"></cc1ataGridColumnIndex> tags.

Someone please help... I've been pulling my hair out and losing sleep
over this problem and I've poured over every post and web page I can
find about this subject, to no avail.

Let me know if any more information is needed.

P.S. This is ASP.NET 1.1, VS.NET 2003

Thank you!

 
Reply With Quote
 
 
 
 
Sundar.k
Guest
Posts: n/a
 
      12-12-2005


"BluegrassNate" wrote:

> Hello all,
>
> I've been working on a custom datagrid (custom web control inherited
> from DataGrid). I am attempting to add a new collection property to
> the control as described all over this group and the web... seems like
> it should be easy but I've been at it for about a week
>
> Here's the problem: I am able to use my custom collection editor to add
> collection items just fine, but the collection refuses to 'rebuild'
> itself when I reopen the aspx file and gives the very helpful error
> ''NonDraggableColumns' could not be initialized". Obviously
> NonDraggableColumns is my collection property.
>
> Here are some relevant fragments:
>
> ASPX code for datagrid looks like this:
>
> <cc1:dhtmldatagrid id="dgResults" runat="server"
> AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True">
> <Columns>
> <asp:BoundColumn DataField="test" HeaderText="test"></asp:BoundColumn>
> </Columns>
> <NonDraggableColumns>
> <cc1ataGridColumnIndex ParentPosition="0"></cc1ataGridColumnIndex>
> </NonDraggableColumns>
> </cc1:dhtmldatagrid>
>
> So the editor did its job and correctly added an item to my custom
> collection, which is simply a collection of DataGridColumnIndex objects
> inherited from CollectionBase. I've provided the proper indexers and
> Add methods, etc.
>
> The DataGridColumnIndex class is very very simple (because I just need
> to get a collection like this working first!) and only has one public
> property - ParentPosition (Int32).
>
> My collection property is defined in my control as follows:
>
> [Editor(typeof(ACS.Bluegrass.Web.Controls.ColumnCol lectionSubsetEditor),
> typeof(System.Drawing.Design.UITypeEditor)),
> DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
> PersistenceMode(PersistenceMode.InnerProperty)]
> public DataGridColumnCollectionSubset NonDraggableColumns
> {
> get
> {
> if (nonDraggableColumns == null)
> {
> nonDraggableColumns = new DataGridColumnCollectionSubset();
> }
>
> return nonDraggableColumns;
> }
> }
>
> Of course, the control class is marked as ParseChildren(true),
> PersistChildren(false).
>
> Everything has the same namespace. The strangest thing is, if I simply
> use and ArrayList instead of my CollectionBase -based collection class,
> the parsing will suceed, BUT only if I manually remove the namespace
> prefix (cc1 from the inner <cc1ataGridColumnIndex
> ParentPosition="0"></cc1ataGridColumnIndex> tags.
>
> Someone please help... I've been pulling my hair out and losing sleep
> over this problem and I've poured over every post and web page I can
> find about this subject, to no avail.
>
> Let me know if any more information is needed.
>
> P.S. This is ASP.NET 1.1, VS.NET 2003
>
> Thank you!
>
>

 
Reply With Quote
 
 
 
 
BluegrassNate
Guest
Posts: n/a
 
      12-14-2005
Finally!

Well I finally got it to work just now, and the problem was that my
object class that the collection is made up of didn't have a default
constructor. I only provided a constructor with a parameter and when I
added just a:

public DataGridColumnIndex() {}

to my class it functions perfectly well. I haven't seen this mentioned
anywhere else but that seemed to do it for me.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
WebControl - CollectionEditor Problem. Changing id property of new added collection item causes not adding item to collection - Sergio ASP .Net Web Controls 0 05-29-2006 06:20 AM
Adding items in collection property during design mode Saimeera ASP .Net 0 05-10-2006 11:34 AM
Collection property "could not be initialized" in design mode for custom datagrid control BluegrassNate ASP .Net Building Controls 0 12-07-2005 11:13 PM
custom control (with collection) do not render at Design time rleblond@jeancoutu.com ASP .Net Building Controls 1 09-27-2005 01:15 PM



Advertisments