Cache the Picker’s Data to Avoid Problems with Events and Actions

Given a SmartForm with the same item view attached to it three times, like rows: View A at top, View B in the center, and View C at bottom. Each view contains a series of controls, including a picker. Events on the view are wired such that the selections of the controls are recorded in a data label as each was made, So a dropdownlist control set to “I”, a radio button list with “am” selected, and a picker control set to “asleep” would give us a value of “I am asleep” in the data label.

I was seeing a peculiar behavior wherein the entire value of the data label in View A was being wiped out after the picker resolved, but the same combination of controls and values were working just fine in subsequent views. The same was also true if I skipped View A and used View B.

I spent quite a while troubleshooting and was able to resolve the problem by setting the picker to cache its data. By caching the data, the picker effectively loads when the view initializes, instead of loading at first use. This just-in-time loading was impacting the rule actions assigned to the picker’s changed event. It is also why I would see the behavior on the first view I used it on, but not on subsequent views.

To set a picker control to cache its data, select it on the SmartForm Designer and look at its properties at lower left. In the Data Source region, click the ellipses button to the right of the SmartObject field to bring up the Configure Data Source dialog. About 3/4 of the way down that dialog, under the Display settings, you should find a checkbox indented to align with the form fields above it. The label simply reads, “Cache the data.” Check the box and click OK to close the Configure Data Source dialog, then finish and check in the view or form.

The picker should now load its data in the form or view’s initialize event, allowing your event actions to proceed unimpeded.