DataBinding: EntityCollection.AddNew doesn't refresh form controls

Posts   
 
    
Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 17-Jan-2007 08:37:08   

Hi all,

I have a form with some textboxes, databound to an EntityCollection. Showing, updating and deleting of entities works fine, but when I call EntityCollection.AddNew(), a new entity is returned by the method, but the texboxes still show the values of the previously selected entity. How can I make them to show the new (empty) entity.

I tried using a bindingsource, binding the controls to it and call BindingSource.AddNew(), but the problem remains.

Does anyone knows how to fix this?

regards,

Peter

BTW: I'm using version 1.0.2005.1 of LLBLGen Pro with Visual Studio 2005, C#.NET 2.0

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Jan-2007 15:25:49   

Please post: 1- A code snippet. 2- RuntimeLibrary version

And make sure EntityCollection.AllowNew is set to true;

Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 17-Jan-2007 16:36:16   

LLBLGen Pro Version 1.0.2005.1 Final, Released on: February 20th, 2006

  • LLBLGen Pro .NET 2.0 Dynamic Query Engine for SqlServer (7/2000/2005/MSDE): 1.0.20051.60111
  • LLBLGen Pro .NET 2.0 ORM Support Classes Library: 1.0.20051.60216

I have a two-tab form: first tab is an overview, bound to a TypedView. The user can then click on a button to view, edit, add or delete an item from the list.

The second tab is a detail-tab, bound to an EntityCollection. When the user wants to edit, view or delete an item, I get the item using:


IPredicateExpression filter = new PredicateExpression();
filter.Add(MyEntityFields.Id == id);
MyEntitycollection.GetMulti(filter);

When he wants to add an item, I just call:

MyEntity newItem = MyEntitycollection.AddNew();
//Set some hidden fields
newItem.SiteID = 1;
newItem.SetNewFieldValue(MyEntityFields.StreetId.FieldIndex, null);
...

As mentioned before, the showing of existing data works fine. It's just the new entity that isn't shown properly.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Jan-2007 16:49:01   

Since you are using .NET 2.0, it's recommended that you use a BindingSource (for 2-way databinding). And use the same code to add a new entity (MyEntitycollection.AddNew()wink

Also please download and use the latest release of 1.0.2005.1, as you are using a rather old version.

Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 19-Jan-2007 10:02:41   

I did the following: - Downloaded latest version of LLBLGen Pro 1.0.2005.1 - Regenerated the code and renewed reference to LLBLGen Pro-Dll's - Added a bindingsource-control to the form - Linked the bindingsource to MyEntityCollection - Bound the controls to the bindingsource - Added a new item using MyEntityCollection.AddNew()

All this didn't help.

I really had to add:

bindingSource.ResetItem(bindingSource.List.Count - 1);

to make the new item visible. confused

Looks a bit redundant to me. A bindingsource is supposed to help you to present your data to the user. So when he adds a new item, it should move to it automatically, IMHO.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Jan-2007 10:31:10   

A bindingsource is supposed to help you to present your data to the user. So when he adds a new item, it should move to it automatically, IMHO.

Now I know what you mean. No I guess the binding source doesn't automatically move to the newly added item. Bad design I guess.