UI Databinding Problem with BO Sort property


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,

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.

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:-

            bo1.FillAll();

            // Set sort order
            bo1.Sort = "CODE";
            bo1.Navigate(MicroFour.StrataFrame.Business.BusinessNavigationDirection.First);

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 - it looks like the UI databindings are only refreshed during the Save operation.

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.

When I remove the bo1.Sort line the problem goes away.

I can build the sort into the BO Fill SQL command but I would be interested to know what I have done wrong.

Thanks in advance,

Aaron

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
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



The safest way to get around this is to disable your sort right before the add, then re-enable it right after.



bo1.Sort = "";

bo1.Add();

bo1.Sort = "CODE";




Alternatively, you could sort on something other than the primary key, but even then you could get some funky behavior depending on what you choose to sort on.



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.



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 Smile.
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
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
Thanks Dustin and Ivan.

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.

Thanks again for the help.

Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
Yep, that would work great. Smile
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