AddNewCore, DataGridView Binding, and AllowNew=True

AddNewCore, DataGridView Binding, and AllowNew=True

Old forum URL: forums.lhotka.net/forums/t/2557.aspx


dlim posted on Tuesday, March 20, 2007

I have a child list (parent is Product and it loads the list) that inherits BusinessListBase:

        ConfigItemList : Csla.BusinessListBase<ConfigItemList, ConfigItem>

I have overridden the AddNewCore method in it to call the Factory NewConfigItem() method in the child object.

                protected override object AddNewCore()
        {
            ConfigItem item = ConfigItem.NewConfigItem();
            Add(item);
            return item;
        }

In the constructors of the ConfigItemList I've added code to set the AllowNew property to true;

                private ConfigItemList()
        {
            this.AllowNew = true;
            MarkAsChild();
        }

        private ConfigItemList(SafeDataReader dr)
        {
            this.AllowNew = true;
            MarkAsChild();
            Fetch(dr);
        }


I've created an ObjectDataSource for the Product and a BindingSource (configItemsBindingSource) that uses the Product as the ObjectDataSource and it's ConfigItems list Property as the ValueMember.  I have a DataGridView whose DataSource is configItemsBindingSource.  I've set the AllowNew property on configItemsBindingSource to true as well.

I get a new item row in my DataGridView, but short of catching the AddingNew event, I cannot add a new row to the data source without getting an exception saying the constructor of ConfigItem is undefined.  The AddNewCore method is never called. 

Am I missing something?  Based on all of the documentation (incl Expert C# 2K5) I've read, all I should have to do to use a factory method in the ConfigItem object is override AddNewCore.  Anyone else have this problem?

I'm using the newest version of CSLA and the .NET 2.0 framework.


dlim replied on Tuesday, March 20, 2007

Nevermind.  It was a stupid mistake.  I had forgot to update the DataSource of the BindingSource to point to the actual instance of my collection.  Once I added the line

configItemsBindingSource.DataSource = _currentProduct.ConfigItems;

the problem went away.

Copyright (c) Marimer LLC