andyhill Posted January 14 Share Posted January 14 I have a need where the user can select from a grid's editor combobox an item of interest and then using the 'validateedit' event I fetch and populate the other specific row cell data relating to the selection = live update of SellPrice. The reason why it is not a DBComboBox is the fact that the user is also allowed to type in an item manually even if it does not exist in the combobox list. So if it exists, then SellPrice etc. is automatically updated in the grid, if not exist then user can type in the SellPrice manually. My code works to a point, but fails to advance to the next cell forcing a repaint, only by mouse clicking the next cell (or TAB Key) does the SellPrice display - our focus is stuck within the editors combobox no matter what we do in code - please advise. procedure TMainForm.grdWorkSheetAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); ... col:= grdWorkSheet.CurrCol; // 1=Quantity, 2=Description, 3=SellPrice if col = 2 then begin UniMainModule.PreItemDescription:= Trim(Params.Values['old']); UniMainModule.PostItemDescription:= Trim(Params.Values['new']); if ( (UpperCase(UniMainModule.PreItemDescription) <> UpperCase(UniMainModule.PostItemDescription)) and (UniMainModule.PostItemDescription <> '') ) then begin if UniMainModule.tblLkUpItems.Locate('Description', VarArrayOf([Trim(UniMainModule.PostItemDescription)]), [loCaseInsensitive]) = True then begin grdWorkSheet.Columns[2].Field.AsString:= UniMainModule.PostItemDescription; grdWorkSheet.Columns[3].Field.AsFloat:= UniMainModule.tblLkUpItems.FieldByName('SellPrice').AsFloat; grdWorkSheet.Columns[4].Field.AsString:= UniMainModule.tblLkUpItems.FieldByName('BASType').AsString; grdWorkSheet.CurrCol:= grdWorkSheet.CurrCol + 1; grdWorkSheet.Repaint; ValidateBusyFlag:= False; ... Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 14 Author Share Posted January 14 Editor closes and remains focused - no amount of code can shift focus to next cell (thus painting new values) - Trying all sorts of tricks - not working grdWorkSheet.Columns[2].Editor.Perform(CM_DialogKey, VK_TAB, 0); After Field values adjusted in code I need to move focus to next column. Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 14 Author Share Posted January 14 Sherzod, please show me how to change focus in grid (setting CurrCol is ignored). Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 15 Share Posted January 15 @andyhill Try creating a simple app for your case and attach here so I can test it. A simple app, without unnecessary codes... Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 18 Author Share Posted January 18 I sent shell project to you privately the other day. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 18 Share Posted January 18 12 minutes ago, andyhill said: I sent shell project to you privately the other day. Yes, I saw. But forgive me for my misunderstanding. It is also inconvenient to require clarification from you. Can you create a gif file or video where we can see the issue? Or also, what do you expect works on VCL? Can you make a simple testcase on VCL to check the difference? Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 18 Author Share Posted January 18 grid.mp4 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 18 Share Posted January 18 Sorry, it's difficult for me to understand your code completely. But maybe I solved your issue, check please. It's possible your assigned events may conflict, I haven't looked. procedure TMainForm.UniFormCreate(Sender: TObject); var MyScript: String; i: Integer; begin UniDBGrid1.JSInterface.JSAddListener('reconfigure', 'function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)'+ '{ '+ ' columns.forEach(function(col){ '+ ' var ed=col.getEditor(); '+ ' if (ed.xtype === "combo"){ '+ ' ed.addListener("select", '+ ' function (combo, record) { '+ ' var _cRow = sender.getSelectionModel().getCurrentPosition().row; '+ ' var _cCol = sender.getSelectionModel().getCurrentPosition().column; '+ ' _cCol+=1; '+ ' /* You must take into account the count of hidden columns */ '+ ' _cCol-=1; '+ ' Ext.defer(function(){sender.editingPlugin.completeEdit()}, 10); '+ ' Ext.defer(function(){sender.editingPlugin.startEdit(_cRow, _cCol)}, 20); '+ ' } '+ ' ) '+ ' } '+ ' }) '+ '} ' ); ////////////////////////////////////////////////////////////////////////////// ... Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 18 Author Share Posted January 18 Fantastic - Thank You Sherzod. Is it possible to do this in the Grid's 'validateevent' after verifying it was the CombBox that triggered the 'validateedit' Event:- MyJSName:= MainForm.grdWorkSheet.JSName; UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);'); I tried this but it had no effect ? Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 19 Author Share Posted January 19 Can we do this UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);'); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 20 Share Posted January 20 On 1/19/2024 at 1:37 AM, andyhill said: I tried this but it had no effect ? How did you try? What code are you using for this? Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 20 Author Share Posted January 20 As I said before, the reconfigure above works great. I asked why can't I do this inside the Grid's "validateedit' Event instead ? UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);'); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 20 Share Posted January 20 41 minutes ago, andyhill said: As I said before, the reconfigure above works great. I know it works, that's not what I'm asking. 42 minutes ago, andyhill said: I asked why can't I do this inside the Grid's "validateedit' Event instead ? UniSession.AddJS('Ext.defer(function(){'+MyJSName+'.editingPlugin.completeEdit()}, 10);'); 2 hours ago, Sherzod said: On 1/19/2024 at 1:37 AM, andyhill said: I tried this but it had no effect ? How did you try? What code are you using for this? Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 20 Author Share Posted January 20 Using Grid.Ext.Events 'validateedit' 'validateedit' Event checks to see if the CurrCol is using a ComboBox editor, if so the Event processes the ComboBox's before and after values A Logic decision is made in code, if required then automatically populating other Grid Cells (on the same row) with new data relating to the new ComboBox value ComboBox Editing is closed <------- this is what your 'reconfigure' Event does now Grid moves on to next cell ALL THIS WORKS USING THE 'reconfigure' Event you gave me earlier. As A Teaching Lesson My additional question was why can't I just use the code below inside the Grid's 'validateedit' Event:- UniSession.AddJS('Ext.defer(function(){'+GridJSName+'.editingPlugin.completeEdit()}, 10);'); instead of relying on the ComboBox's 'reconfigure' Event to close the editor ? Is it a timing issue ? Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 24 Author Share Posted January 24 Please advise Sherzod Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 24 Share Posted January 24 1 hour ago, andyhill said: Please advise The problem statement itself is not very clear to me. Quote Link to comment Share on other sites More sharing options...
andyhill Posted January 24 Author Share Posted January 24 How Do I Force ComboBox to completeEdit (using AddJS) ? 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.