Current filter:
                                You should refresh the page.
                                  • Description:
                                    How to Retrieve the Record Values for the Selected Grid Rows

                                    Table Views of the ExpressQuantumGrid allow you to select one or more records. If you want to retrieve dataset values for the selected records there are a couple of approaches for doing this depending on how your Grid is configured and the specifics of your application.
                                    A View retrieves the data used to display rows from an object called the Data Controller which you can get from the View's DataController property. The approach you take will depend on the Data Controller's data loading mode, which will be either grid mode where the Data Controller only retrieves sufficient rows to fill the View client area, or the default mode where the Data Controller retrieves all rows. This mode is set using the GridMode parameter of the DataController, the default is GridMode = False.
                                    Default data loading mode
                                      ie: View.DataController.DataModeController.GridMode = False
                                    This means that the Data Controller works in default mode. Here data is loaded from the underlying dataset and stored in memory as a rectangular matrix. You can easily access the required data via the DataController.Values property.
                                    You can obtain selected records via the <aView>.Controller.SelectedRecords list. This gives you an instance of the TcxCustomGridRecord object (or a descendant depending on the class of View you are querying).
                                    This approach requires you to follow these steps:

                                    1. Get a selected record index:
                                    RecIdx := View.Controller.SelectedRecords[i].RecordIndex;

                                    NOTE: This index represents the index of the record within the Data Controller's data matrix. Do not confuse it with the Record.Index property that represents the visual record index (which is affected by sorting and grouping).
                                    2. Get the index of the required column (Data Controller item):

                                    ColIdx := View.DataController.GetItemByFieldName(AFieldName).Index;
                                    3. Get the required value from the Data Controller:
                                    OutputVal := View.DataController.Values[RecIdx, ColIdx];

                                    NOTE: The Data Controller stores only the values for which View columns are required. However, it may be necessary to get a dataset value for a field that is not bound to any column (and thus, its values are not loaded by the Data Controller's Values matrix). To do this, you should use the dataset's methods (Locate or Lookup) to get the required field values. You can locate the corresponding dataset record using the ID value of the Data Controller record.

                                    RecID := View.DataController.GetRecordId(RecIdx);

                                    The ID represents the values of the Data Controller's key fields (do not forget to initialise the DataController.KeyFieldNames property). Further, you may use the obtained variant value when calling the Locate or Lookup methods:

                                    OutputVal := ADataSet.Lookup(View.DataController.KeyFieldNames, RecID, AFieldName);

                                    Grid data loading mode
                                      ie: View.DataController.DataModeController.GridMode = True
                                    The Data Controller is in grid mode and loads a fixed number of dataset records into memory, usually only sufficient to display the current View state. Since, not all records are stored in memory, it is impossible to use the <aView>.Controller.SelectedRecords list. Instead, you should use the <aView>.DataController.GetSelectedBookmark property, which provides a list of dataset bookmarks (TBookmarkStr). Here are the steps to obtain values for a particular selected record:

                                    1. Get a bookmark corresponding to the selected record:
                                    Bkm := View.DataController.GetSelectedBookmark(ASelectedRecordIndex);
                                    2. Verify whether the bookmark is valid:
                                    if ADataSet.BookmarkValid(TBookmark(Bkm)) then
                                    3. Assign the bookmark to the dataset's Bookmark property. This will move the dataset cursor to the corresponding record.
                                    4. Obtain the value of the required field(s) using standard dataset methods:
                                    OutputVal := ADataSet.FieldByName(AFieldName).Value;

                                    NOTE: When repositioning the dataset cursor in code, you probably do not want the Grid to be updating its display accordingly so use the following methods to prevent multiple refreshing of the View and data reloading:

                                    View.BeginUpdate; View.DataController.BeginLocate; try // make changes here... finally View.DataController.EndLocate; View.EndUpdate; end;

                                    More details about the Data Controller's BeginLocate/EndLocate methods can be found in the following article:
                                      How to prevent reloading data when calling the dataset's Locate method
                                    The attached sample demonstrates how to use the described approaches. The comments in the code clarify the destination of the methods being used.

                                • Valery Titov 09.17.2014

                                  Code examples what may probably help you:

                                • Igor Pakemonoff 01.01.2017

                                  In gridmode = false better use DataController.DataSet.DisableControls  and DataController.DataSet.EnableControls
                                  instead BeginUpdate / EndUpdate
                                  When I use  BeginUpdate / EndUpdate changes in tables not refreshing

                                  var i: Integer; v: variant; begin   inherited;   with CRDBGrid1DBTableView1 do   begin //  BeginUpdate;   DataController.BeginLocate;   DataController.DataSet.DisableControls;   if Controller.SelectedRowCount > 0 then   for i := 0 to PRED(Controller.SelectedRowCount ) do   begin // Grid mode          DataController.DataSet.Bookmark := DataController.GetSelectedBookmark(i);         v := DataController.GetRecordId(Controller.SelectedRecords[I].RecordIndex);         DataController.DataSet.Locate(DataController.KeyFieldNames, v, []);          DataController.DataSet.Edit;          DataController.DataSet['USED']:= true;          DataController.DataSet.Post;   end;      DataController.EndLocate; //     EndUpdate; //           2 Jan 2017 Igor // Better use BeginUpdate / DataController.DataSet.DisableControls  DataController.DataSet.EnableControls/EndUpdate  instead EndUpdate // - for chage fields in cxGrid    DataController.DataSet.EnableControls;   end;

                                0 Solutions

                                Creation Date Importance Sort by