0
votes

D5, ZEOS 6.6, SQLite.

I have srcAccount.AutoEdit = False;

I have All Edit functions set to False in the TDBGrid Options. Only options are set to true are Indicator, grind lines and Titles.

I have a form with a few TDBEdits and a TDBGrid on it showing all the current accounts.

When the user clicks the "New" button for a new account I have

dbedAcct.SetFocus;
tblAccounts.Insert;

If, after clicking the New button, the user wants to scroll to check Account names OR happens to click in the grid, it saves the new data and drops out of Insert mode.

How can I stop this happening? I need for them to be able to check account names.

Or, is this a bug with D5? If so, how do I work around it?

I also tried using SMDBGrid and it does exactly the same thing. http://www.scalabium.com/smdbgrid.htm

1

1 Answers

4
votes

I need for them to be able to check account names.

You can't do that using the same grid + dataset if you're allowing the user to do data entry to the grid. You are creating this problem for yourself by trying to use the grid for data entry and look-up at the same time. A simple solution is to use the grid for look-up and have a separate form (or panel on the same form as the grid) for doing the inserts, and these need to be connected to different dataset instances.

The thing is, you can't scroll around a dataset (as you need to do you look up other records) while it's in the middle of inserting a record. The dsBrowse state needed for a dataset to allow scrolling around and the dsInsert state needed to insert are mutually exclusive. Attempting to scroll the dataset will automatically post the pending insert, as you've found.

So, you actually need two dataset instances, one for lookup and one for inserts. If you use two client-side ClientDataSet instances, it can be quite straightforward because of the ease with which you can copy the data from one to the other using the CDS's Data property (cdsLookup.Data := cdsLive.Data), so making a local copy for look-up is trivial. Or, if you prefer you can use a cloned cursor - see http://edn.embarcadero.com/article/29416