dbadvgrid key field not updating from database

I have not been able to figure out why this is happening.
I insert a record to the grid the db is a mysql and has an autoincrement key so i set the key to 0 at the time of insert. If i do not, then it errors on field must have a value.
But when the record is posted the dbadvgrid still shows it as a 0 rather than the generated key value. I can see the value in the mysql db update but the grid does not update. Then I get a key violation on the next insert because the grid has 2 records with the key 0 even though this is NOT true when you view the data in the database at the same time. What could cause this?

Do you insert this record via the grid or via code? If with code, what exact code? Is grid.PageMode = true? Is this the latest version of the TDBAdvGrid?

In code just by calling dataset.insert. Then in the after insert, i set the field to zero with fieldbyname('id').AsInteger := 0;
PageMode is true.
dbAdvgrid version is 2.5.1.0
TMS 10.4.0.0 September 2020

Did you check Required setting?

Yes, i changed all those settings and stopped putting a 0 in for the id field and left it blank but still the key violation persists. The grid is not reading back the value of the id after mysql generates it. So when you go to enter the next row, you have 2 records with either a 0 or a blank. Either way, a key error. The problem is on scroll without the save process. If i manually save the record in code by clicking button, the key value comes to grid. If i put the button click in the dataset before scroll, it does not work. I don't see why that would be the case. The row post of the dbADVgrid must supersede the onscroll? Maybe that is the problem? This screen shot is where the key violation breaks during the scroll to the next record or insert.

Does changing the property DBAdvGrid.EditPostMode affect this?

Changing post mode to epCell does not change the behavior. The auto increment ID is generated in the table, but does not come back to the grid.

I do not understand it and I wonder if this is really an issue in our component but rather something in the DB driver. When you connect a DBLabel to the autoinc field, do you see the value of the label having a correct value when you perform insert?

I do not think the value is generated until the post. It is blank on insert.
The issue is if I insert and stay on the record, and while on the new record, post, applyupdates, and refresh the clientdataset, then reload the dbadvgrid the new autoinc value comes to the grid fine.
If I click on a different record without saving - the value does not return to the grid. Even thought the db generates it. I try to execute the same code in the before onscroll, but the eponrow seems to take the db out of edit mode. Maybe i should save without checking state of dataset in onscroll. I will do some more testing.

The issue is that the rowpost is happening before the beforescroll event. So i have no way to detect the scroll for only when in edit/insert and refresh the client dataset to get the data to return to the grid. A condition for in dsedit or dsinsert within the before scroll is never met because the grid posts the data before you get that event. I am looking into putting my refresh in the onstatechange instead.

I have put a plain dbedit on the form as you suggested and this is giving more troubling results. I am seeing the id field not the same in the grid as the dbedit after an edit and post. They seem to remain different unless i go back to the top of the grid and then it sync's back up. Also the rows below the one i posted no longer get a record indicator in column0.

I'm sorry but not being able to reproduce this makes it extremely hard to understand this let alone, give advice how to remedy this.
Can you change the setup of for example the ADOEditing demo so this behavior can be reproduced and then provide us these details or modified sample?

Yes, i understand. I am trying to reduce the code to isolate the issue better. Adding BeginUpdate and dataset.disablecontrols at the start of the afterpost and Reload, enablecontrols, EndUpate at the end of the afterpost has solved some of the issues.

The ADOEditing demo doesn't work right for me either. I opened the demo, ran it and inserted a row. When i moved to the next cell, the grid moved all over the place.


See screen record of the test. I can't imagine that is the way it is supposed to work. ?

Set grid.EditPostMode = epRow