I am making a app in Delphi 6 + MySQL database using standard data-aware components and dbExpress. The app allows a users to view records in a grid and edit data (insert and/or delete records) client side. These data edits are then only written to database on clicking the submit button. All of this works fine and has the following setup:
Controls: 1. DBGrid1 linked to a DataSource1 to display data visually. 2. DataSource1 is linked to ClientDataSet1 to offer data for DBGrid to display. 3. ClientDataSet1 is linked to DataSetProvider1 to provide client-side data for editing. 4. DataSetProvider1 is linked SQLDataSet1 which selects records from a single DB table. 5. SQLDataSet1 is linked to SQLConnection to provide connection to MySQL database.
Actions: 1. User inserts a record: I use ClientDataSet1.InsertRecord; 2. User deletes a record: I use ClientDataSet.Delete; 3. User submits data: I use ClientDataSet1.ApplyUpdates(-1);
This all works great in terms of handling data & posting data (with the inclusions of a small hack on DataSetProvider1BeforeUpdateRecord to delete records).
NOW FOR MY PROBLEM: When the user first loads the form, the DBGrid1 displays all original records, removes all deleted records. But when the user inserts a new record in ClientDataSet1, a blank record is displayed in DBGrid1. The actual data is not lost or set as NULLS as when you ClientDataSet1.ApplyUpdates, this record is correctly written to the DB.
I know TClientDataSet has a data property for original data and a Delta property for edited data. Can these two properties with data by displayed in a single DBGrid at one time & still allowing the user to edit the data?
I have looked at 30+ resources and demo apps & all avoid this issue. Can this be done?