Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Set Focus on field

Posted on by 375

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
    AhmedSaeed 375 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
    Gunjan Bhattachayya 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
    AhmedSaeed 375 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
    Gunjan Bhattachayya 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans