Ticket A291
Visible to All Users

How to add or delete records in Smart Refresh mode

created 21 years ago (modified 2 years ago)

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:

  1. 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);
  1. Use the Data Controller's methods to manage the data in the dataset. They are:
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:

Delphi
TcxDataEditValueSource = (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

Comments (2)

    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.

    Delphi
    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;
    DevExpress Support Team 10 years ago

      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.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.