﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 09:34:39 GMT</lastBuildDate><ttl>20</ttl><item><title>BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable</title><link>http://forum.strataframe.net/FindPost20278.aspx</link><description>Hi,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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:-&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The first record remains the current row – see screenshot “Grid2”.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The new record is added to the end of the grid but it is not the current row.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Aaron</description><pubDate>Thu, 23 Oct 2008 17:17:26 GMT</pubDate><dc:creator>Aaron Young</dc:creator></item><item><title>RE: BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable</title><link>http://forum.strataframe.net/FindPost20310.aspx</link><description>It would only affect you if you have the BO wrapped in a BBS.&amp;nbsp; I never do this unless I actually run into this issue (which I can't think of a time where I have).&amp;nbsp; So no, just do this when you need it.&amp;nbsp; 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.</description><pubDate>Thu, 23 Oct 2008 17:17:26 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable</title><link>http://forum.strataframe.net/FindPost20299.aspx</link><description>So Trent, does this apply to all cases where &lt;FONT color=#000000&gt;PrimaryKeyIsUpdatable is being used, or only if I would be using a grid with that specific BO?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#000000&gt;In other word, should I add that code to my base BO if using PrimaryKeyIsUpdatable?&lt;/FONT&gt;</description><pubDate>Thu, 23 Oct 2008 13:32:52 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable</title><link>http://forum.strataframe.net/FindPost20288.aspx</link><description>Clever man - again! :)</description><pubDate>Thu, 23 Oct 2008 10:27:19 GMT</pubDate><dc:creator>Aaron Young</dc:creator></item><item><title>RE: BindingSource problem with PrimaryKeyIsAutoIncremented and PrimaryKeyIsUpdatable</title><link>http://forum.strataframe.net/FindPost20285.aspx</link><description>OK, this isn't actually a bug, but rather how the BusinessBindingSource receives instruction from the grid.&amp;nbsp; It is a simple fix though.&amp;nbsp; 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.&amp;nbsp; If you call the PauseChangedEvents and ResumeChangedEvents methods, it will fix your problem.&amp;nbsp; In the SetDefaultValues of the BO, just add this code:&lt;P&gt;[codesnippet]&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/P&gt;&lt;P&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt; (PrimaryKeyIsUpdatable)&lt;BR&gt;&lt;/FONT&gt;{&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.PauseChangedEvents();&lt;BR&gt;prod_pk = Count + 1;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.ResumeChangedEvents();&lt;BR&gt;}&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;That will get you the behavior that you are looking for.</description><pubDate>Thu, 23 Oct 2008 10:09:47 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>