BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable


Author
Message
Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Hi,

When a business object’s PrimaryKeyIsAutoIncremented = False and PrimaryKeyIsUpdatable = True, it appears to upset current row binding through a bindingsource when a new record is added. The attached sample project hopefully will show this.

Run the application against the StrataFrameSample database. When the form runs, it will show an Infragistics UltraGrid bound to the sample products through a bindingsource. PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable are set to the defaults of True and False respectively. Click on the New button and a new record is added to the bottom of the grid and it is the active row. Screenshot “Grid1” shows this. So far so good.

Stop the application and change PrimaryKeyIsAutoIncremented to False and PrimaryKeyIsUpdatable to True and re-run. This will enable code in the business objects SetDefaultValues() to assign a manual ID value. Now click the New button and two things happen:-

1.       The first record remains the current row – see screenshot “Grid2”.

2.       The new record is added to the end of the grid but it is not the current row.

Basically, the change from an auto generated key to a manual key has resulted in the new record not being made the current row in the grid. Have I missed something?

Thanks in advance,

Aaron

Attachments
WindowsApplication1.zip (108 views, 720.00 KB)
Grid1.png (136 views, 35.00 KB)
Grid2.png (134 views, 37.00 KB)
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
OK, this isn't actually a bug, but rather how the BusinessBindingSource receives instruction from the grid.  It is a simple fix though.  When you manually assign the PK value, the grid thinks that a CurrentChange has taken place because the PK is not being updated within the internal initialization.  If you call the PauseChangedEvents and ResumeChangedEvents methods, it will fix your problem.  In the SetDefaultValues of the BO, just add this code:

if (PrimaryKeyIsUpdatable)
{
this.PauseChangedEvents();
prod_pk = Count + 1;
this.ResumeChangedEvents();
}

That will get you the behavior that you are looking for.

Aaron Young
Aaron Young
StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)StrataFrame User (435 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Clever man - again! Smile
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
So Trent, does this apply to all cases where PrimaryKeyIsUpdatable is being used, or only if I would be using a grid with that specific BO?

In other word, should I add that code to my base BO if using PrimaryKeyIsUpdatable?

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It would only affect you if you have the BO wrapped in a BBS.  I never do this unless I actually run into this issue (which I can't think of a time where I have).  So no, just do this when you need it.  The reason I haven't run into this during my app development is because I use grids in a very limited number of situations and have a more controlled environment when I do and a report will never have this problem since it is not creating new records, etc.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search