﻿<?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?)  » UI Databinding Problem with BO Sort property</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 12:42:33 GMT</lastBuildDate><ttl>20</ttl><item><title>UI Databinding Problem with BO Sort property</title><link>http://forum.strataframe.net/FindPost18318.aspx</link><description>Hi,&lt;/P&gt;&lt;P&gt;I have a strange problem because of one line of code and I can't see why. Basically, when I use the BO.Sort method it causes the UI refresh of the BO bindings to fail when a new record is added. When the BO.Sort line is removed, it works correctly.&lt;/P&gt;&lt;P&gt;I have a very simple SF maintenance form with a single BO and a single textbox bound to a field. In the ParentFormLoading I have the following code:-&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bo1.FillAll();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Set sort order&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bo1.Sort = "CODE";&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bo1.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.First);&lt;/P&gt;&lt;P&gt;When the form loads the textbox correctly shows the first record and the navigation tools work correctly. However, when a new record is added the textbox always shows the value from the very first record instead of the new blank record - regardless of which record I was on at the time the New button was clicked. For example, if I navigate to the 10th record and click New, the textbox suddenly shows the value from the 1st record. When I click Save with no data entry, the textbox shows an empty value and for the first time the UI is set to the new record&amp;nbsp;- it looks like the UI databindings are only refreshed during the Save operation.&lt;/P&gt;&lt;P&gt;I have checked in the AfterAddNew BO method and the new record is correctly added and is the current record. However, the UI always shows the very 1st record until the Save is actioned.&lt;/P&gt;&lt;P&gt;When I remove the bo1.Sort line the problem goes away.&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;I can build the sort into the BO Fill SQL command but I would be interested to know what I have done wrong.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Aaron</description><pubDate>Tue, 05 Aug 2008 08:33:26 GMT</pubDate><dc:creator>Aaron Young</dc:creator></item><item><title>RE: UI Databinding Problem with BO Sort property</title><link>http://forum.strataframe.net/FindPost18331.aspx</link><description>Yep, that would work great. :)</description><pubDate>Tue, 05 Aug 2008 08:33:26 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>RE: UI Databinding Problem with BO Sort property</title><link>http://forum.strataframe.net/FindPost18324.aspx</link><description>Thanks Dustin and Ivan.&lt;/P&gt;&lt;P&gt;That helps to explain it. I think I will stop using the Sort method and hard code the sort order directly in the Fill() method of the BO as it sounds like that will work.&lt;/P&gt;&lt;P&gt;Thanks again for the help.</description><pubDate>Mon, 04 Aug 2008 17:30:41 GMT</pubDate><dc:creator>Aaron Young</dc:creator></item><item><title>RE: UI Databinding Problem with BO Sort property</title><link>http://forum.strataframe.net/FindPost18323.aspx</link><description>Hey Aaron.&lt;/P&gt;&lt;P&gt;Some links that might help you:&lt;/P&gt;&lt;P&gt;&lt;A href="http://forum.strataframe.net/FindPost18218.aspx"&gt;http://forum.strataframe.net/FindPost18218.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://forum.strataframe.net/FindPost11815.aspx"&gt;http://forum.strataframe.net/FindPost11815.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope it helps. ;)</description><pubDate>Mon, 04 Aug 2008 17:23:32 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: UI Databinding Problem with BO Sort property</title><link>http://forum.strataframe.net/FindPost18322.aspx</link><description>This is happening since your BO is sorting on the primary key of the table. Whenever you do an add, it is adding a new record with a "-1" primary key which, when sorted, gets immediately stripped out of the CurrentView. :w00t:&lt;br&gt;
&lt;br&gt;
The safest way to get around this is to disable your sort right before the add, then re-enable it right after. &lt;br&gt;
&lt;br&gt;
[codesnippet]bo1.Sort = "";&lt;br&gt;
bo1.Add();&lt;br&gt;
bo1.Sort = "CODE";[/codesnippet]&lt;br&gt;
&lt;br&gt;
Alternatively, you could sort on something [i]other[/i] than the primary key, but even then you could get some funky behavior depending on what you choose to sort on. &lt;br&gt;
&lt;br&gt;
The key here is that a sort or filter of a business object will be immediately applied whenever you add or remove a record, and, as such, any filters or sorts should always be taken into account when modifying the contents of the BO.&lt;br&gt;
&lt;br&gt;
There a bunch of forum topics out there on this particular subject covering everything from alternative work arounds to why we do it this way, but that should at least point you in the right direction :).</description><pubDate>Mon, 04 Aug 2008 17:13:06 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item></channel></rss>