Skip to main content

Notifications

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

  • Avi Pinhas Profile Picture
    Avi Pinhas 310 on at
    Re: Re: How to retain cursor position?

    Thanks again.

    I have tried your solution and it works perfectly.

    Avi

  • Avi Pinhas Profile Picture
    Avi Pinhas 310 on at
    Re: Re: How to retain cursor position?

    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

  • Re: How to retain cursor position?

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans