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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Set Focus on field

(0) ShareShare
ReportReport
Posted on by 383

Hellow everyone,

in the below screen i need to set focus on barcode Number once open the form and once add value to it set focus on Quantity filed and also once click enter to add new line and focus on Barcode Number

pastedimage1607260462269v1.png

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    Hi Ahmed,

    Have you tried controlName.setFocus()? For setting focus on the quantity field you can use the same statement in the modified method of the Bar code field.

  • AhmedSaeed Profile Picture
    383 on at

    The auto declaration property for the control is NO an i can't change  it

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,429 on at

    Can You try this code to access the form control from the control name?

    public FormControl findFormControl(FormControlName _name)
    {
        int controlId = formRun.controlId(_name);
        FormControl control = formRun.control(controlId);
        return control;    
    }

  • Suggested answer
    AhmedSaeed Profile Picture
    383 on at

    Hi Gunjan,

    i solved the problem by the following code:

    1- to set focus on the field once the form opened i copy Activited event in form data source and add this code

    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]

       public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

       {

           FormRun  fr = sender.formRun() as FormRun;

           fr.design().controlName(formControlStr(SalesTable,SalesLine_modItemBarCode)).setFocus();

       }

    2- to set focus on Quantity filed and  copy the Modified event for the control and add this code

      [FormControlEventHandler(formControlStr(SalesTable, SalesLine_modItemBarCode), FormControlEventType::Modified)]
        public static void SalesLine_modItemBarCode_OnModified(FormControl sender, FormControlEventArgs e)
        {
            FormRun  fr = sender.formRun() as FormRun;
            fr.design().controlName(FormControlstr(SalesTable,SalesLine_SalesQty)).setFocus();
        }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 426 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 358

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 353 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans