Posted by webmaster Guido on June 16, 2003
: I have a DBGrid connected to a paradox TTable, and I have noticed that when the Dataset is in Insert or Edit mode, pressing the Tab key will perform an automatic Post of the Dataset, instead of going to the next column to insert/edit the other information. With the default settings, an automatic "Post" is only caused by pressing TAB if you are in the last column. I'll leave it up to you to find out what causes the other Posts, but here are some general ideas: * As you noted, you should leave the DBGrid's option "dgTabs" set to True, otherwise the user can't use the Tab and Shift+Tab keys for navigation in the grid. * But it's not only the TAB key that should worry you, because automatic posting happens whenever you leave the current row of the DBGrid (if you go to another record)! That means that all these actions post the record: - there is a mouse click in another row; Solution: check the contents of all the fields right before a record is posted, and block the posting if necessary. The best place to do this is in the BeforePost event of the table, like this: procedure TFormMain.Table1BeforePost(DataSet: TDataSet); begin if (Table1.FieldByName('Hour').AsString = '') or (Table1.FieldByName('Name').AsString = '') or (Table1.FieldByName('What').AsString = '') then begin ShowMessage('Please enter something in ALL the fields'); Abort; // no Post if any of the fields is empty end; end; Find related articles Search for: DBGrid Dataset Table |
|