Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 14, 2005 03:13 PM by BluegrassNate
Dec 08, 2005 06:35 PM|LINK
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">
<asp:BoundColumn DataField="test" HeaderText="test"></asp:BoundColumn>
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:
public DataGridColumnCollectionSubset NonDraggableColumns
if (nonDraggableColumns == null)
nonDraggableColumns = new DataGridColumnCollectionSubset();
<div class=qt id=qhide_25417 style="DISPLAY: block">}
</div>Of course, the control class is marked as ParseChildren(true),
Everything has the same namespace. The strangest thing is, if I simply
use an ArrayList instead of my CollectionBase -based collection class,
the parsing will succeed, BUT only if I manually remove the namespace
prefix (cc1:) from the inner <cc1:DataGridColumnIndex
ParentPosition="0"></cc1:DataGridColumnIndex> tags in HTML mode.
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
Dec 09, 2005 02:52 AM|LINK
Your class and collection property attributes and implementation of the collection property as readonly and self-instantiating upon the first reference all appear to be correct. Have you provided an override of the AddParsedSubObject method?
Dec 14, 2005 01:20 PM|LINK
Thanks for replying.
Yes, I've tried that. I added a break point on the first line and it never gets hit! I'm debugging design time functionality in another instance of VS.NET. Am I doing something wrong or should AddParsedSubObject be called?
Dec 14, 2005 03:13 PM|LINK
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:
it functions perfectly well. I haven't seen this mentioned anywhere else but that seemed to do it for me.