Description:
How to Add or Delete Records When in Smart Refresh Mode
Answer:
Applies to:
When the Data Controller of a View is working in Smart Refresh mode
<aView>.DataController.DataModeController.GridMode = False
<aView>.DataController.DataModeController.SmartRefresh = True
it does not reload all the records when its underlying dataset is updated. Only the modified records are reloaded. This gives a significant performance increase, especially when operating with large quantities of data.
However, the Smart Refresh feature has a drawback: If records are managed not via the Data Controller (for instance, when a user presses the Insert button in a Grid - to insert a new record), but instead directly via the dataset, the Data Controller does not recognize the changes made.
In this case, you may use either of the following approaches to be sure that a View is synchronized with its dataset:
- Call the Data Controller's UpdateItems method after modifying the dataset. This, however, forces the Data Controller to reload all of the records.
Delphi<aView>.DataController.UpdateItems(False);
- Use the Data Controller's methods to manage the data in the dataset. They are:
- Append
- Insert
- Post
- Cancel
- DeleteFocused
- DeleteSelection
The DB Data Controller's record values can be populated by calling the Data Controller's SetEditValue method:
Delphi<aView>.DataController.Append; <aView>.DataController.DataController.SetEditValue(aItemIndex, aValue, evsValue); <aView>.DataController.Post;
NOTE: The 3rd parameter of the SetEditValue method requires a value of the TcxDataEditValueSource type that is declared in the cxDataUtils unit as follows:
DelphiTcxDataEditValueSource = (evsValue, evsText, evsKey);
Most of its elements are for internal use only. You should use only the evsValue item in your code.
See also:
How to Insert a Record into an Active View
How to display an empty row when the underlying dataset is empty
A343
I tried option 2 above and it was working fine for about a week.
It is now throwing an error and terminating the program. My code is below.
Mostly there is no error message, however sometime I get the message: RecordIndex out of range.
I did nothing to change any other feature of the program.
cxgARAPatientsDBBandedTableView1.Styles.OnGetContentStyle:=nil; cxgARAPatientsDBBandedTableView1.DataController.Append; cxgARAPatientsDBBandedTableView1.DataController.SetEditValue(idx, cWhat, evsValue); cxgARAPatientsDBBandedTableView1.DataController.SetEditValue(idxID, iActionID, evsValue); try cxgARAPatientsDBBandedTableView1.DataController.Post; except on e:exception do begin showMessage(e.Message); end; end;
Hello Barry,
To process your recent post more efficiently, I created a separate ticket on your behalf: RecordIndex out of range while using Smart Refresh. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.