web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to retain cursor position?

(0) ShareShare
ReportReport
Posted on by 310

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

I have the same question (0)
  • Denis Patrakov Profile Picture
    on at

    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.

  • Avi Pinhas Profile Picture
    310 on at

    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

  • Avi Pinhas Profile Picture
    310 on at

    Thanks again.

    I have tried your solution and it works perfectly.

    Avi

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Volodya Profile Picture

Volodya 2

#2
tgudwanski Profile Picture

tgudwanski 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans