ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV 2024 feature!
Help / WINDEV Tutorial / Tutorial - WINDEV application: Managing data
  • Lesson 5 - Creating a drop-down menu
  • Overview
  • Creating a drop-down menu
  • Creating an option to print a report
  • To sum up

Tutorial - WINDEV application: Managing data

Lesson 5 - Creating a drop-down menu
We will cover the following topics:
  • Creating a drop-down menu.
  • Printing a report programmatically
Durée de la leçon 30 min
Overview
In the previous lesson, we created a report to list customers. But this report has not yet been integrated into the application. The user has no way of opening it.
To print this report, we will use a very common feature in Windows applications: the drop-down menu.
We will create a drop-down menu in the Menu window of "WD Full Application". We will modify it to print a report. Then, we'll see how to print a report programmatically.
Creating a drop-down menu
Once our report is complete, we will create a menu in the "WIN_Menu" window to directly print the report.
To insert a drop-down menu in "WIN_Menu":
  1. Open "WIN_Menu" in the editor (double-click its name in the "Project explorer" pane, for example).
  2. On the "Window" tab, in the "Bars and menus" group, expand "Main menu" and select "Add main menu".
  3. A menu is inserted into the window, below the title bar. This menu contains an option named "Menu".
Let's add the different menu options. First, let's add a menu option for exiting the application. This option will be a sub-entry of the "Menu" option.
  1. In the editor, select the "Menu" option.
  2. Right-click to open the context menu and select "Transform to expand a submenu".
  3. In the input area that appears, type "Exit".
  4. We are going to associate this menu option with the "Alt + F4" shortcut:
    • Select the "Exit" option.
    • Right-click to open the context menu and select "Option description".
    • In the "General" tab, in the "Keyboard shortcut" area, select "F4" and check "Alt".
      Keyboard shortcut
    • Validate.
Now let's write the code of this option:
  1. Select "Exit".
  2. Right-click to open the context menu.
  3. Select "Code". The code editor appears.
  4. Write the following WLanguage code in the "Select a menu" event:
    // Requires user confirmation to exit the application
    IF YesNo(No, "Exit application?") = Yes THEN
    // End of application
    EndProgram()
    END
    Let's take a look at this WLanguage code:
    • YesNo is used to establish a dialog with the user by asking a question. The user can answer the question via 2 buttons: yes or no.
    • EndProgram (called if the user clicks "Yes") is used to end the application.
Creating an option to print a report
We will now create the options for printing the report:
  1. Select the "Menu" option.
  2. Right-click to open the context menu.
  3. Select "Add an option after".
  4. In the input area, type "Reports".
    New menu option
  5. Select the "Reports" option:
  6. Right-click to open the context menu.
  7. Select "Transform to expand a submenu".
  8. In the input area that is displayed, type "List of customers". Press Enter to validate.
    New menu option
The report will be printed via the "List of customers" option. Let's write the corresponding WLanguage code:
  1. Select the "List of customers" option in the editor.
  2. Right-click to open the context menu.
  3. Select "Code". The code editor appears.
  4. Write the following code in the "Selecting the menu" event:
    // The report is displayed in the report viewer
    iDestination(iViewer)

    // Prints the report
    RPT_list_of_customers.Print()
    Let's analyze this code:
    • iDestination allows you to configure the print destination. You can generate a report to be printed:
      • in a text file,
      • in HTML format,
      • in PCL format,
      • in PDF, RTF, XLS or XML format,
      • on a fax.
      In our case, the report will be generated in the report viewer window.
    • <Report>.Print is used to print reports.
Test the window and its menu options by clicking Test element in the quick access buttons.
To sum up
Completed project
Do you want to check the end result of the steps described here?
A completed project is available. This project contains the different windows created in this lesson. To open the completed project, go to the home page and click "Tutorial", then in "Tutorial - WINDEV application: Manage data", double-click "Full application - Answers".
In this lesson, we discovered how to create a drop-down menu and allow the user to print a report. In the next lesson, we will see how to show statistics using the Chart and Pivot Table controls.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 2024
Comments
Click [Add] to post a comment

Last update: 12/15/2023

Send a report | Local help