tblCompany.Edit; tblCompany.FieldByName('name').Value := txtNewValue.Text; tblCompany.Post; txtNewValue.Text := ''; txtHoneyPot.SetFocus; btnSaveEdit.Visible := false; txtNewValue.Visible := false;
The line that is causing you grief is "btnSaveEdit.Visible := false;". When the user clicks on the button, the focus shifts to the button and making it invisible when it receives the focus will cause the problem. Note: the button only gets the focus AFTER the OnClick event is fired. When it comes to UI design I am not a big fan of making things appear and disappear based on a program state, but if you must hide your button, I would suggest using actions. In the OnUpdate event of the action determine whether to hide the button - check first to see if the button has focus. if it has, set the focus to the next control, then hide the button (by setting the action's Visible property to False). ----- Original Message ----- From: Tracey Maule To: Multiple recipients of list delphi Sent: Tuesday, October 15, 2002 9:39 AM Subject: [DUG]: Cannot focus a disabled or invisible window Hi there... I have a form with a DBGrid showing values from one table (tblCompany) I am currently trying to provide new record/edit functionality with code, rather than use one of those ugly DBNavigators. My problem is with the edit. I have an edit button displayed always, when the user selects edit, an invisible edit box is made visible, along with a "save changes" button. (someone told me once not to allow users to edit/add within a grid...) my problem is that when i click save changes i receive two error messages (the original focus message (subject line) plus a "dataset not in edit mode" one) i suspect the focus problem is because i am making the edit box invisible while focus is still set to it, however i tried setting focus to another edit box and the error did not change. heres the few lines of code i have tblCompany.Edit; tblCompany.FieldByName('name').Value := txtNewValue.Text; tblCompany.Post; txtNewValue.Text := ''; txtHoneyPot.SetFocus; btnSaveEdit.Visible := false; txtNewValue.Visible := false; please lend me the benifit of your decades of experience and knowledge here Tracey Software Developer / Web Master Logis [EMAIL PROTECTED] (025) 213-1065 --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/