Simple databinding fails in vs2005

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 31-Jan-2006 00:23:47   

Hi guys,

Any idea why this code generates an exception:

            EntityCollection coll = new EntityCollection();
            coll.Add(new UserEntity()); // simple user entity
            dataGridView1.DataSource = coll;

The exception is generated within EntityCollection.GetItemProperties method because listAccessors argument is null.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Jan-2006 07:15:19   

Please provide the text of the exception and a stack trace. Thanks and good luck

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 31-Jan-2006 08:00:55   

mihies wrote:


                EntityCollection coll = new EntityCollection();
                coll.Add(new UserEntity()); // simple user entity
                dataGridView1.DataSource = coll;

I believe that you need to specify the factory when creating the EntityCollection object

EntityCollection coll = new EntityCollection(New FactoryClasses.UserEntityFactory);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 31-Jan-2006 10:40:00   

Jim's correct, you need to specify a factory.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 31-Jan-2006 15:33:39   

Otis wrote:

Jim's correct, you need to specify a factory.

Thanks guys, I knew I was missing something stupid. Perhaps you might enhance documentation (or did I miss it) and raise meaningfull exception when the entry parameter (listAccessors) of EntityCollection.GetItemProperties is null.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 31-Jan-2006 17:08:45   

That parameter can be null (it is when a property is read from an object in the collection bound to the grid directly), it's just that in that case it tries to create a dummy entity to produce the actual properties for the ITypedList implementation, though as the factory is null, it fails. I'll see if I can add code which throws a more meaningfull exception there. simple_smile

(edit): looking at the code, it's a bug. It should use the instance in the collection if no factory is there, not just use the factory. It now assumes the factory is there if there are instances in the collection. I'll fix this.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 01-Feb-2006 10:18:37   

Otis wrote:

(edit): looking at the code, it's a bug. It should use the instance in the collection if no factory is there, not just use the factory. It now assumes the factory is there if there are instances in the collection. I'll fix this.

Yes, I was assuming this behaviour (looking at first item)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 02-Feb-2006 11:47:28   

Fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro