View RSS Feed

Development Team Blog

How to Create a Checkbox in Your Report?

Rating: 2 votes, 5.00 average.
Often a picture says more than a 1000 words... Well, a checkbox is not a picture but if well used it can draw the same kind of attention to the reader of the report results. Assume you want a checkbox on results of your Visual Report Writer report, how could you do this?

First look at the following screenshot that shows what I mean with using a checkbox in your report output.

If the phone number is a free number, that is when it starts with (800), the report shows a checkbox. The report is based on the vendor table in the standard order entry example that comes with Visual DataFlex.

To create this I made two functions in Visual Report Writer. One function that results in printing the X and one function that manages the line style of the border. The line style of the border? Yes, to create a checkbox I decided to place a border on all four sides of the object if the 'X' is printed.

In the report create a function named CheckboxBorderStyle and place the following code in the function body:
Code:
if (left ({Vendor.Phone_Number}, 5) = '(800)') then
    return vrwBorderSingle
else
    return vrwBorderNone
end
It says to return the constant for a single border if the '800' value is in the first 5 characters of the phone number. The advantage of creating one function for returning the border style is that we can easily replace it in one location.

The second function to create is called FreePhoneNumberCheckbox and contains the following code as function body:
Code:
if (left ({Vendor.Phone_Number}, 5) = '(800)') then
    return 'X'
else
    return ''
end
This function is really put in the report on the body line. If you would print the report now it would print an 'X' or nothing. So a little formatting is required to make it show as a checkbox. For that open the field properties of the object added the report and change the following things;
1. Make the text centered (horizontal alignment)
2. Make the text font bold (font tab-page)
3. Use the CheckboxBorderStyle for the four border style functions on the border tab-page.

Each border style function is the same. The contents should be:
Code:
return {@CheckboxBorderStyle}
and the field properties dialog looks like:


Finally, I will enclose the report to this blog. Note that if you want to run the report you need to change the path to the data-source. If you don't do that you get a file not open error.
Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	CheckboxInResults.jpg 
Views:	2454 
Size:	80.7 KB 
ID:	6111   Click image for larger version. 

Name:	ChecboxFunctionInUse.jpg 
Views:	1453 
Size:	77.0 KB 
ID:	6112  
Attached Thumbnails Attached Files

Comments