3 min read

Microsoft Dynamics NAV 2009 Programming Cookbook

Microsoft Dynamics NAV 2009 Programming Cookbook

Build better business applications with NAV

  • Write NAV programs to do everything from finding data in a table to integration with an instant messenger client
  • Develop your own .NET code to perform tasks that NAV cannot handle on its own
  • Work with SQL Server to create better integration between NAV and other systems
  • Learn to use the new features of the NAV 2009 Role Tailored Client
  • Easy-to-read recipes with detailed explanations and images
  • Maximize your learning with short tutorials that tell you exactly what you need to know without all of the fluff

How to do it…

  1. Add a frame to the form.

  2. Set the following properties on the textbox:

  3. Add a label to the frame with the caption “Frame 1”.
  4. Set the following properties on the Label:

  5. Copy the frame and paste two copies of it on the form.
  6. Change the labels in the new frames to be Frame 2 and Frame 3.
  7. Change the Name properties of the frames to Frame2 and Frame3 respectively.
  8. Your form should look like the one shown in the following screenshot:

  9. Add four buttons to the form beneath Frame 1. The name and caption properties on each should be Back, Next, Finish, and Cancel respectively.

  10. Add the following code to the OnOpenForm trigger:

    CurrForm.Frame1.XPOS := 0;
    CurrForm.Frame1.YPOS := 0;
    CurrForm.Frame2.XPOS := 0;
    CurrForm.Frame2.YPOS := 0;
    CurrForm.Frame3.XPOS := 0;
    CurrForm.Frame3.YPOS := 0;

    CurrForm.HEIGHT := CurrForm.Cancel.YPOS +
    CurrForm.Cancel.HEIGHT + 220;
    CurrForm.WIDTH := CurrForm.Cancel.XPOS +
    CurrForm.Cancel.WIDTH + 220;

    WizardStep := 1;
    ShowStep(TRUE);

    
    
  11. Add a function named ShowStep that takes in a boolean value named Show as a parameter.
  12. Add the following code to the function:

    CASE WizardStep OF
    1: BEGIN
    CurrForm.Frame1.VISIBLE := Show;
    CurrForm.Frame2.VISIBLE := NOT Show;
    CurrForm.Frame3.VISIBLE := NOT Show;
    CurrForm.Back.ENABLED := NOT Show;
    CurrForm.Next.ENABLED := Show;
    CurrForm.Finish.ENABLED := NOT Show;
    END;

    2: BEGIN
    CurrForm.Frame1.VISIBLE := NOT Show;
    CurrForm.Frame2.VISIBLE := Show;
    CurrForm.Frame3.VISIBLE := NOT Show;
    CurrForm.Back.ENABLED := Show;
    CurrForm.Next.ENABLED := Show;
    CurrForm.Finish.ENABLED := NOT Show;
    END;

    3: BEGIN
    CurrForm.Frame1.VISIBLE := NOT Show;
    CurrForm.Frame2.VISIBLE := NOT Show;
    CurrForm.Frame3.VISIBLE := Show;
    CurrForm.Back.ENABLED := Show;
    CurrForm.Next.ENABLED := NOT Show;
    CurrForm.Finish.ENABLED := Show;
    END;
    END;

    
    
  13. Add the following code to the OnPush trigger of the Back button:

    ShowStep(FALSE);
    WizardStep -= 1;
    ShowStep(TRUE);

    
    
  14. Add the following code to the OnPush trigger of the Next button:

    ShowStep(FALSE);
    WizardStep -= 1;
    ShowStep(TRUE);

    
    
  15. Add the following code to the OnPush trigger of the Finish button:

    CurrForm.CLOSE;

    
    
  16. Add the following code to the OnPush trigger of the Cancel button:

    CurrForm.CLOSE

    
    
  17. Save and close the form.

How it works…

The form contains three frames, only one of which is visible at any given time. In the design view, you can see that our form is quite wide and tall, but that would not look right when displaying a wizard form. That’s why we place code in the OnOpenForm trigger.

The first set of lines places all of the frames on top of each other. The middle set changes the width and height of the form. Finally, the third sets the appropriate frames to be visible or not and enables the correct buttons.

Our custom method ShowStep decides what should be visible and what should not. It is just a large CASE statement based on the WizardStep variable. On the first frame for example, we can’t move backwards to disable the Back button. We can’t finish until we get to the last frame so that the Finish button is disabled until that point.

On the Back and Next buttons we decrement and increment the WizardStep variable so that the ShowStep method knows what to do. Other than the initial opening of the form we always call the function with FALSE as a parameter to “undo” what is currently displayed, change the WizardStep variable, and call the function with parameter TRUE to display new information.

Summary

In this part of the article series we covered:

  • Creating a Wizard-style Form

In the next part we will cover Updating Parent and Subform.


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here