Hi,
I have developed a production reporting form that has a string control. The production order Barcode is scanned into this control and Enter key is pressed. Relevant methods are executed and the reported line is displayed in a grid.
I would like the cursor to return to the Barcode string control. Setfocus method of the control does not work and rather the cursor moves to the first column of the grid.
How do I position the cursor back to the string control?
Thanks
Avi
*This post is locked for comments
Thanks again.
I have tried your solution and it works perfectly.
Avi
Many thanks. I will try this.
I found another (not elegant) workaround. I used infolog to display a dummy message. Then I have used the setfocus() and then killed the infolog.
You solution is definitly better.
Thanks.
Avi
SetFocus() usually does work but the problem seems to be in the sequence of actions and the time when you call setFocus(). Enter key moves focus in AX from one control to another (unless you have a default button on a form) but in your case it might be processed after you call SetFocus(). You can work around this by using setTimeOut(): create a method on a form that will call setFocus() on your control and call this method indirectly via setTimeOut() f.e. in the executeQuery() method of the DataSource bound to the grid:
// on a form
void setFocus2BarCodeStrCtrl()
{;
BarCodeStrCtrl.setFocus();
}
// on a datasource
public void executeQuery()
{
QueryBuildDataSource qbds;
;
if ( this.query()
&& BarCodeStrCtrl.text() != ''
)
{
// set range by the BarCodeStrCtrl.text()
}
super();
element.setTimeOut( identifierstr(setFocus2BarCodeStrCtrl), 100, true );
}
The most important is the 3rd parameter of setTimeOut() - it makes setFocus2BarCodeStrCtrl() to be called only when the AX client is idle (i.e. is not processing a database request or something else). A sample form works fine in my case.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156