Programming Guide : 7. Working with List Views and Tree Views : Listview Fields : How the Listview Example Works
 
Share this page                  
How the Listview Example Works
The remainder of this section refers to the listview_example frame of the Listview_Treeview_Demo application. Use the Frame Editor to examine the listview_example frame online and its 4GL script as you read.
In the Frame Editor, the listview_example frame is displayed:
The listview_example frame contains an empty listview field named lview and a matrix field that contains a number of image trim fields. The bitmaps of the image trim fields are used with the listview. When the frame runs, the matrix field is hidden.
Use the Property Inspector to examine the ColAttributes attribute of the listview field. ColAttributes is an array of ListviewColAttr objects, and determines the number and order of columns in the listview field. The ListviewColAttr contains the column width and header text, and lets you specify how the text is aligned in the column header.
The listview_example frame uses a user class, name_and_extension. This class has the following attributes:
last_name
Specifies a person's last name
first_name
Specifies a person's first name
extension
Specifies a telephone extension
image_index
Specifies an integer
Now, to display the frame script to understand the following discussion, click Tools, Script on the floating menu bar.
The following script is displayed:
The script declares a variable, names, as an array of name_and_extension. The populate_name_array procedure loads the names array with data.
The set_listview_images procedure sets up the SmallImageList and LargeImageList arrays of the listview field. SmallImageList and LargeImageList are arrays of bitmapobjects. In this example, the bitmaps display letters, and the nth item of each array is a bitmap representing the nth letter of the alphabet.
The next step in setting up the listview field is to associate bitmaps with each item in the names array. This example uses the bitmap corresponding to the first letter of the last name. The set_image_indexes procedure calculates the appropriate bitmap index for each item in the names array and stores the index in the image_index attribute.
Initially, the name array is sorted by last name. The sort_names_array procedure sorts the array using the values of sort_column and sort_order to determine how the array is sorted.
Finally, the load_listview procedure is called to load the listview field with data.