Problem:
This article documents two simple extensions to the Micro Focus Dialog System ListView control/object. Both new features are implemented by modifying the standard generated ListView control program within Micro Focus Net Express.
Resolution:
This article covers the ability to change the column headings and to set focus on the ListView control. This uses a modified version of the standard Micro Focus Dialog System ListView demo to illustrate the extensions detailed in this article. You may wish to download the attached demo so that you can review the code while reading.
Our first addition to the ListView functionality is the ability to change the column headings after the control has been created. This required us to add a new function (UPDATE-HEADER) to the ListView control program (LVIEWCTL.CBL).
Firstly, open the LVIEWCTL.CBL source file within Net Express, and review the new code. All the code that has been added to this program is prefixed with the letters "pc" in columns 1 and 2.
First, add a new condition to the control program's EVALUATE statement so that the new function can be accessed from Dialog System:
...
when "UPDATE-HEADER"
perform Update-List-Header
...
The code required to change the column headings is very similar to the "Add-List-Header" section. Start by copying this code, and creating a new "Update-List-Header" section .
If you look at the code you will see that you basically do the following:
Set the font you intend to use.
Set the heading for each column.
Adjust the column width to match the heading/decorations.
To change the header text for a particular column, perform three steps.
1. Create a character array object to store the new column header:
invoke CharacterArray "fromBuffer"
using i
Term-Field
returning aCharArray
The Term-Field variable contains the new column heading text, and is passed from the Dialog System screenset.
2. Invoke the SetLabel method for each column object and pass it the character array created previously:
invoke lvItem-Object(k) "SetLabel"
using aCharArray
3. Tidy up by deleting (FINALIZE) the character array:
invoke aCharArray "finalize"
returning aCharArray
Now, add the code that calls the new function to our Dialog System screenset:
MOVE "CODE" LVITEM-TEXT(1)
MOVE 4 LVITEM-LENGTH(1)
MOVE "DESCRIPTION" LVITEM-TEXT(2)
MOVE 30 LVITEM-LENGTH(2)
MOVE "QUANTITY" LVITEM-TEXT(3)
MOVE 4 LVITEM-LENGTH(3)
MOVE "UNIT PRICE" LVITEM-TEXT(4)
MOVE 6 LVITEM-LENGTH(4)
SET OBJECT-REFERENCE(1) LVIEW-01-OBJREF
MOVE "UPDATE-HEADER" CALL-FUNCTION(1)
MOVE 4 NUMERIC-VALUE(1)
CALLOUT "lviewctl" 3 $NULL
As you can see, this is almost identical to the code that creates headers and consists of:
Defining each new column heading within the LVITEM-TEXT/LENGTH tables.
Passing the appropriate object reference for our control program to use.
Passing the number of columns to be modified.
Calling the ListView control program (passing the entire screenset data block).
You can see the above code in action by compiling and running the supplied demo. Once the main window appears simply click on the "Original Headers" and "New Headers" push buttons to see the column headings alter.
The next function is much simpler and only requires two lines to implement. This sets the focus on the ListView control (without having to tab to it), and allows the control to be manipulated via the keyboard (cursor up/down etc.).
Unfortunately you cannot use the Dialog System SET-FOCUS function for this, therefore we need to add an extension to the control program. As before, add a new condition to the EVALUATE statement:
...
when "SET-FOCUS"
invoke Object-Reference "SetFocus"
...
All we have to do is to invoke the SetFocus method of the object reference that has been passed from Dialog System. In this case, the reference to the ListView control.
The Dialog System code simply needs to set the object reference, define the function and then CALL the ListView control program:
SET OBJECT-REFERENCE(1) LVIEW-01-OBJREF
MOVE "UPDATE-HEADER" CALL-FUNCTION(1)
CALLOUT "lviewctl" 3 $NULL
To obtain the example used in this article please download the attached demo file: ListViewExtensions.zip