andyhill Posted April 20, 2022 Share Posted April 20, 2022 Trying to process Grid Keyboard SPACE pressed event. dbGridPurchases.ClientEvents.ExtEvents.Clear; s:= 'keypress=function keypress(e, t, eOpts)'#13#10 + '{ '#13#10 + ' ajaxRequest(sender, '#39'_KeyPress_'#39', ["key="+e.key]); '#13#10 + '} '; dbGridPurchases.ClientEvents.ExtEvents.Add(s); Please advise - thanks in advance Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 21, 2022 Share Posted April 21, 2022 Hello, Why don't you use server events? Quote Link to comment Share on other sites More sharing options...
andyhill Posted April 21, 2022 Author Share Posted April 21, 2022 I suppose different solutions are possible (including monitoring Form KeyPress) BUT after seeing procedure dbGridInvoicesKeyPress(Sender: TObject; var Key: Char); not work I then tried the JS way as shown above which also does not work ? I assume I have done something wrong ? I would like to do this the JS way if you would be so kind and show me how please - thanks Sherzod. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 21, 2022 Share Posted April 21, 2022 You have to understand that there are different events, say when the grid is active, and when the cell is in edit mode. Which one you ask, I don't know. Quote Link to comment Share on other sites More sharing options...
andyhill Posted April 21, 2022 Author Share Posted April 21, 2022 Grid Active and not in edit mode, need to flip Tag field for focused ROW with SpaceBar via event Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 21, 2022 Share Posted April 21, 2022 1 hour ago, andyhill said: need to flip Tag field for focused ROW with SpaceBar via event Hmm, sorry I don't understand your case. Quote Link to comment Share on other sites More sharing options...
andyhill Posted April 21, 2022 Author Share Posted April 21, 2022 dbGridPurchases.ClientEvents.ExtEvents.Clear; s:= 'keypress=function keypress(e, t, eOpts)'#13#10 + '{ '#13#10 + ' ajaxRequest(sender, '#39'_KeyPressed_'#39', ["key="+e.getKey()]); '#13#10 + '} '; dbGridPurchases.ClientEvents.ExtEvents.Add(s); ... ////////////////////////////////////////////////////////////////////////////// procedure TfMain.dbGridPurchasesAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); ... if EventName = '_KeyPressed_' then begin if Params.Values['key'] = ' ' then begin ReadOnly:= False; if UniMainModule.tblPurchases.ReadOnly = True then begin ReadOnly:= True; UniMainModule.tblPurchases.ReadOnly:= False; end; if UniMainModule.dsPurchases.DataSet.State in [dsInsert, dsEdit] then begin // DB // do nothing end else begin UniMainModule.tblPurchases.Edit; end; if UniMainModule.tblPurchases.FieldByName('Tag').AsBoolean = True then begin UniMainModule.tblPurchases.FieldByName('Tag').AsBoolean:= False; end else begin UniMainModule.tblPurchases.FieldByName('Tag').AsBoolean:= True; end; UniMainModule.tblPurchases.Post; if ReadOnly = True then begin UniMainModule.tblPurchases.ReadOnly:= True; end; end; end; Quote Link to comment Share on other sites More sharing options...
andyhill Posted April 21, 2022 Author Share Posted April 21, 2022 Sherzod, do you understand from my code above ? The Grid is not in edit mode, user scrolls Grid Rows, user presses SPACE bar on a desired Row, I capture the Key Event and test for SPACE Key - if pressed I then flip the Table Row Field TAG to True or False accordingly. Please advise Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 Hi, I will try to understand your case and let you know. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 22, 2022 Share Posted April 22, 2022 8 hours ago, andyhill said: The Grid is not in edit mode, user scrolls Grid Rows, user presses SPACE bar on a desired Row, I capture the Key Event and test for SPACE Key Have you tried this? procedure TMainForm.UniDBGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = VK_SPACE then ShowMessage('spacebar pressed') end; Quote Link to comment Share on other sites More sharing options...
andyhill Posted April 22, 2022 Author Share Posted April 22, 2022 I need key press not key down. procedure TfMain.dbGridPurchasesKeyPress(Sender: TObject; var Key: Char); NEVER FIRES ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.