Skip to main content

Notifications

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
    AhmedSaeed Profile Picture
    383 on at
    RE: Set Focus on field

    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();
        }

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Set Focus on field

    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;    
    }

  • AhmedSaeed Profile Picture
    383 on at
    RE: Set Focus on field

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

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Set Focus on field

    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.

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 the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

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

#1
Martin Dráb Profile Picture

Martin Dráb 487 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 310

#3
Saalim Ansari Profile Picture

Saalim Ansari 291

Overall leaderboard

Product updates

Dynamics 365 release plans