Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
Complete the form below to send this article, Microsoft Dynamics NAV 2009: Creating a Wizard-style Form, to a friend (or to yourself). We will never share your details (or your friend's) with anyone. For more information, read our Privacy Policy.
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.
| Read more about this book |
(For more resources on Microsoft Dynamics, see here.)
How to do it...
- Add a frame to the form.

- Set the following properties on the textbox:

- Add a label to the frame with the caption "Frame 1".
- Set the following properties on the Label:

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

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

- 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); - Add a function named ShowStep that takes in a boolean value named Show as a parameter.
- 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; - Add the following code to the OnPush trigger of the Back button:
ShowStep(FALSE);
WizardStep -= 1;
ShowStep(TRUE); - Add the following code to the OnPush trigger of the Next button:
ShowStep(FALSE);
WizardStep -= 1;
ShowStep(TRUE); - Add the following code to the OnPush trigger of the Finish button:
CurrForm.CLOSE;
- Add the following code to the OnPush trigger of the Cancel button:
CurrForm.CLOSE
- 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:
In the next part we will cover Updating Parent and Subform.
Further resources on this subject:
About the Author :
Books From Packt
|
|
|




Post new comment