How do you loop through a cxgrids records? i.e. make delphi program go through/check each record in the cxgrid from top to bottom.
I have a cxgrid which is displaying records from a tadquery which is talking to a database table if this helps in anyway.
Sample code to do this for a TcxGridDBTableView in a TcxGrid, and also to iterate an DataSet below. Both of these samples will work regardless of whether the DataSet is filtered or not.
The sample for the TcxGrid assumes you've pulled the grid from the palette, added a TcxDBTableView to it, added the dataset's columns to it and left all grid properties in the Object Inspector at their defaults, except the KeyFieldNames of the TableView, which needs setting to the DataSet's primary key, in my case "FilesID". This is so as to be able to identify the dataset record for a given row in the TableView - you obtain the key value, ID, for the row like so:
The ID value is then used by the call to CDS1.Locate() to retrieve the record.
The TBookmark is used to note the current CDS record before the operation and to return to it afterwards. The calls to DisableControls and EnableControls are to prevent the cxGrid (and any other DB-aware controls connected to the CDS) from being changed while the operation is in progress.
Btw, I know this is not what you asked, but if you want to iterate a dataset without doing it using a TcxGrid, it's actually much simpler: