Microsoft Dynamics NAV 2009: Creating a Wizard-style Form

Exclusive offer: get 50% off this eBook here
Microsoft Dynamics NAV 2009 Programming Cookbook

Microsoft Dynamics NAV 2009 Programming Cookbook — Save 50%

Build better business applications with Microsoft Dynamics NAV 2009 with this book and eBook

$35.99    $18.00
by Matt Traxinger | October 2010 | Cookbooks Microsoft

This article series by Matt Traxinger, author of Microsoft Dynamics NAV 2009 Programming Cookbook, shows you how to create displays that will allow your users to interact with the data.

A wizard is a form that steps you through specific sections using Next and Back buttons. Here we will show you how to design a form which will do exactly that.

 

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
        Read more about this book      

(For more resources on Microsoft Dynamics, see here.)

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:


    Microsoft Dynamics NAV 2009 Programming Cookbook Build better business applications with Microsoft Dynamics NAV 2009 with this book and eBook
    Published: October 2010
    eBook Price: $35.99
    Book Price: $59.99
    See more
    Select your format and quantity:

    About the Author :


    Books From Packt


    Microsoft Dynamics NAV 2009 Application Design
    Microsoft Dynamics NAV 2009 Application Design

    Microsoft Dynamics NAV Administration
    Microsoft Dynamics NAV Administration

    Microsoft Dynamics GP 2010 Cookbook
    Microsoft Dynamics GP 2010 Cookbook

    Microsoft Dynamics AX 2009 Development Cookbook
    Microsoft Dynamics AX 2009 Development Cookbook

    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Microsoft Windows Workflow Foundation 4.0 Cookbook

    Applied Architecture Patterns on the Microsoft Platform
    Applied Architecture Patterns on the Microsoft Platform

    WCF 4.0 Multi-tier Services Development with LINQ to Entities
    WCF 4.0 Multi-tier Services Development with LINQ to Entities

    Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
    Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications


    Code Download and Errata
    Packt Anytime, Anywhere
    Register Books
    Print Upgrades
    eBook Downloads
    Video Support
    Contact Us
    Awards Voting Nominations Previous Winners
    Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
    Resources
    Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software