Tabular IQ

Overview

The ListView class represents a list view control.

Base Class

FormControl

Constructor

ListView(x_pos : Integer, y_pos : Integer, width : Integer, height : Integer)

Arguments

x_pos
The x position of the control.
y_pos
The y position of the control.
width
The width of the control.
height
The height of the control.

Events

ListView.columnClick
Fired when a column is left-clicked.
ListView.columnRightClick
Fired when a column is right-clicked.
ListView.itemActivate
Fired when a list item is activated.
ListView.itemBeginLabelEdit
Fired at the beginning of a list item label edit.
ListView.itemEndLabelEdit
Fired at the end of a list item label edit.
ListView.itemRightClick
Fired when a list item is right-clicked.
ListView.itemSelect
Fired when a list item is selected.
ListView.keyDown
Fired when a key is pressed.

Properties

ListView.LargeIcon
A flag representing that the ListView should be created in large icon mode.
ListView.SmallIcon
A flag representing that the ListView should be created in small icon mode.
ListView.Details
A flag representing that the ListView should be created in details mode (single or multiple column list with column headers).
ListView.List
A flag representing that the ListView should be created in list mode (single or multiple column list without column headers).
ListView.AlignLeft
A flag representing that a column in the ListView should be left-aligned (ListView.Details and ListView.List modes only).
ListView.AlignCenter
A flag representing that a column in the ListView should be center-aligned (ListView.Details and ListView.List modes only).
ListView.AlignRight
A flag representing that a column in the ListView should be right-aligned (ListView.Details and ListView.List modes only).

Methods

ListView.addColumn
Adds a column to the ListView
ListView.addItem
Adds a ListViewItem to the ListView.
ListView.clear
Deletes all items from a list view control
ListView.deleteColumn
Deletes a column from the ListView
ListView.deleteItem
Deletes a list view item
ListView.deselectAllItems
Deselects all the items in the list view control
ListView.deselectItem
Deselects the specified list view item
ListView.findItem
Finds an item with the specified text.
ListView.getItem
Retrieves a list view item
ListView.getItemCount
Returns the number of items in the list view
ListView.getItems
Returns all ListViewItem objects in the list view control
ListView.getLabelEdit
Returns whether the item labels may be edited
ListView.getSelectedIndex
Gets the index of the selected item in the listbox.
ListView.getSelectedItem
Returns the first selected ListViewItem object after the specified index in the list view control
ListView.getSelectedItems
Returns the selected ListViewItem objects in the list view control
ListView.getView
Returns the current view mode of the list view control.
ListView.insertItem
Inserts a ListViewItem into the ListView.
ListView.isItemSelected
Indicates whether or not the specified ListViewItem object is selected
ListView.selectItem
Selects the specified list view item
ListView.setLabelEdit
Sets whether the item labels may be edited
ListView.setView
Sets the view mode of the list view control
ListView.sortItems
Sorts the items in the list view control

Inherited Methods

FormControl.captureMouse
Captures the mouse on this form control.
FormControl.disablePaint
Disables the window from redrawing itself.
FormControl.enablePaint
Enables the window to redraw itself.
FormControl.getBackgroundColor
Gets the background color of the form control.
FormControl.getClientSize
Gets the client size of the form control.
FormControl.getEnabled
Indicates whether or not a form control is enabled.
FormControl.getFont
Gets the default font for the text of form control.
FormControl.getForegroundColor
Gets the foreground color of the form control.
FormControl.getMaxSize
Gets the maximum size of the form control.
FormControl.getMinSize
Gets the minimum size of the form control.
FormControl.getMousePosition
Gets the mouse position relative to this form control.
FormControl.getNativeHandle
Gets the native handle of the window/control
FormControl.getPosition
Gets the position of a form control.
FormControl.getSize
Gets the size of the form control.
FormControl.invalidate
Invalidates a form control, which will cause it to be repainted on the next paint event.
FormControl.refresh
Refreshes a form control, which immediately repaints the entire form control.
FormControl.releaseMouse
Releases the mouse from being captured on this form control.
FormControl.setBackgroundColor
Sets the background color of the form control.
FormControl.setClientSize
Sets the client size of a form control.
FormControl.setEnabled
Enables or disables the form control.
FormControl.setFocus
Sets the focus to the form control.
FormControl.setFont
Sets the default font for the text of the form control.
FormControl.setForegroundColor
Sets the foreground color of the form control.
FormControl.setMaxSize
Sets the maximum size of a form control.
FormControl.setMinSize
Sets the minimum size of a form control.
FormControl.setPosition
Sets the position of a form control relative to the the form control's parent.
FormControl.setSize
Sets the size of a form control.
FormControl.show
Shows or hides the form control.
FormControl.update
Updates a form control, which will immediately repaint any invalid areas.

Example

// the folder bitmap is built once and reused for every item
let folder_bitmap = null;

function getFolderBitmap() {
    if (!folder_bitmap) {
        folder_bitmap = new Bitmap(`
            "16 16 6 1",
            "  c None",
            "! c #000000",
            "# c #808080",
            "$ c #C0C0C0",
            "% c #FFFF00",
            "& c #FFFFFF",
            "                ",
            "                ",
            "  #####         ",
            " #%$%$%#        ",
            "#%$%$%$%######  ",
            "#&&&&&&&&&&&&#! ",
            "#&%$%$%$%$%$%#! ",
            "#&$%$%$%$%$%$#! ",
            "#&%$%$%$%$%$%#! ",
            "#&$%$%$%$%$%$#! ",
            "#&%$%$%$%$%$%#! ",
            "#&$%$%$%$%$%$#! ",
            "#&%$%$%$%$%$%#! ",
            "##############! ",
            " !!!!!!!!!!!!!! ",
            "                "`);
    }

    return folder_bitmap;
}


class MyForm extends Form {
    list = null;
    text = null;

    last_sort_order = false;
    last_sort_column = -1;

    constructor() {
        super("ListView Test", 100, 100, 700, 520);
        this.setMinSize(500, 360);

        // create list view and add some columns
        this.list = new ListView();
        this.list.setView(ListView.Details);
        this.list.addColumn("Test Column", 200, ListView.AlignLeft);
        this.list.addColumn("Test Column 2", 200, ListView.AlignLeft);
        this.list.addColumn("Test Column 3", 200, ListView.AlignLeft);
        this.add(this.list);

        // add some items
        const bitmap = getFolderBitmap();
        this.list.addItem(new ListViewItem("Finch", bitmap));
        this.list.addItem(new ListViewItem("Bluebird", bitmap));
        this.list.addItem(new ListViewItem("Goose", bitmap));
        this.list.addItem(new ListViewItem("Sparrow", bitmap));
        this.list.addItem(new ListViewItem("Hummingbird", bitmap));
        this.list.addItem(new ListViewItem("Duck", bitmap));

        // connect events
        this.list.keyDown.connect(this, this.onKeyDown);
        this.list.itemSelect.connect(this, this.onItemSelect);
        this.list.itemActivate.connect(this, this.onItemActivate);
        this.list.itemRightClick.connect(this, this.onItemRightClick);
        this.list.itemBeginLabelEdit.connect(this, this.onItemBeginLabelEdit);
        this.list.itemEndLabelEdit.connect(this, this.onItemEndLabelEdit);
        this.list.columnClick.connect(this, this.onColumnClick);
        this.list.columnRightClick.connect(this, this.onColumnRightClick);

        // text box for event output
        this.text = new TextBox("", 0, 0, 140, 140);
        this.text.setMultiline();

        // some extra buttons

        const additem_button = new Button("Add Item");
        additem_button.click.connect(this, this.onAddItem);

        const changeitem_button = new Button("Change Item");
        changeitem_button.click.connect(this, this.onChangeItem);

        const deleteitem_button = new Button("Delete Item");
        deleteitem_button.click.connect(this, this.onDeleteItem);

        const deleteall_button = new Button("Delete All");
        deleteall_button.click.connect(this, this.onDeleteAll);

        const exit_button = new Button("Exit");
        exit_button.click.connect(this, this.onExit);

        // create button layout
        const button_layout = new BoxLayout(Layout.Horizontal);
        button_layout.add(additem_button);
        button_layout.addSpacer(8);
        button_layout.add(changeitem_button);
        button_layout.addSpacer(8);
        button_layout.add(deleteitem_button);
        button_layout.addSpacer(8);
        button_layout.add(deleteall_button);
        button_layout.addStretchSpacer();
        button_layout.add(exit_button);

        // create main layout
        const main_layout = new BoxLayout(Layout.Vertical);
        main_layout.addSpacer(8);
        main_layout.add(this.list, 1, Layout.Expand | Layout.Left | Layout.Right, 8);
        main_layout.addSpacer(8);
        main_layout.add(this.text, 0, Layout.Expand | Layout.Left | Layout.Right, 8);
        main_layout.addSpacer(8);
        main_layout.add(button_layout, 0, Layout.Expand | Layout.Left | Layout.Right, 8);
        main_layout.addSpacer(8);

        this.setLayout(main_layout);
    }

    onColumnClick(sender, event_args) {
        const column_to_sort = event_args.index;

        // clicking the same column again reverses the sort order
        const sort_order = (column_to_sort === this.last_sort_column)
                               ? !this.last_sort_order
                               : true; // ascending

        this.list.sortItems(column_to_sort, sort_order);

        this.last_sort_order = sort_order;
        this.last_sort_column = column_to_sort;
    }

    onColumnRightClick(sender, event_args) {
        this.addLogLine(`Column right clicked; index = ${event_args.index}`);

        const sortasc_item = new MenuItem("Sort Ascending");
        const sortdec_item = new MenuItem("Sort Descending");
        const deletecol_item = new MenuItem("Delete Column");

        sortasc_item.index = event_args.index;
        sortasc_item.sort_order = true;
        sortasc_item.click.connect(this, this.onDoColumnSort);

        sortdec_item.index = event_args.index;
        sortdec_item.sort_order = false;
        sortdec_item.click.connect(this, this.onDoColumnSort);

        deletecol_item.index = event_args.index;
        deletecol_item.click.connect(this, this.onDoColumnDelete);

        const menu = new Menu();
        menu.add(sortasc_item);
        menu.add(sortdec_item);
        menu.addSeparator();
        menu.add(deletecol_item);

        menu.popup(this.list);
    }

    onDoColumnSort(sender, event_args) {
        this.list.sortItems(sender.index, sender.sort_order);
    }

    onDoColumnDelete(sender, event_args) {
        this.list.deleteColumn(sender.index);
    }

    onKeyDown(sender, event_args) {
        this.addLogLine(`Key down; Char code = ${event_args.keyCode}` +
                        ` shiftDown(${event_args.shiftDown})` +
                        ` controlDown(${event_args.controlDown})` +
                        ` altDown(${event_args.altDown})`);

        // handle user pressing Del key
        if (event_args.keyCode === 127) {
            this.list.deleteItem(event_args.index);
        }
    }

    onItemSelect(sender, event_args) {
        this.addLogLine(`Item selected; index = ${event_args.index}`);
    }

    onItemActivate(sender, event_args) {
        this.addLogLine(`Item activated; index = ${event_args.index}`);
    }

    onItemRightClick(sender, event_args) {
        this.addLogLine(`Item right clicked; index = ${event_args.index}`);

        const menu_item1 = new MenuItem("Test Menu Item 1");
        const menu_item2 = new MenuItem("Test Menu Item 2");
        const menu_item3 = new MenuItem("Delete Listview Item");

        menu_item3.item_number = event_args.index;
        menu_item3.click.connect(this, this.onRightClickDelete);

        const menu = new Menu();
        menu.add(menu_item1);
        menu.add(menu_item2);
        menu.addSeparator();
        menu.add(menu_item3);

        menu.popup(this.list);
    }

    onRightClickDelete(sender, event_args) {
        this.list.deleteItem(sender.item_number);
    }

    onItemBeginLabelEdit(sender, event_args) {
        this.addLogLine(`Begin label edit; index = ${event_args.index}`);
    }

    onItemEndLabelEdit(sender, event_args) {
        this.addLogLine(`End label edit; index = ${event_args.index}`);
    }

    onAddItem(sender, event_args) {
        const caption = `Test Item ${this.list.getItemCount() + 1}`;
        this.list.addItem(new ListViewItem(caption, getFolderBitmap()));
    }

    onDeleteItem(sender, event_args) {
        for (const item of this.list.getSelectedItems()) {
            this.list.deleteItem(item);
        }
    }

    onChangeItem(sender, event_args) {
        let counter = 0;
        for (const item of this.list.getSelectedItems()) {
            counter++;
            item.setText(`${item.getText()} Changed Text`);
            item.setColumnText(1, `Hello ${counter}`);
            item.setColumnText(2, `Hello ${counter}`);
        }
    }

    onDeleteAll(sender, event_args) {
        this.list.clear();
    }

    addLogLine(s) {
        this.text.setText(`${this.text.getText()}${new Date()} - ${s}\n`);
    }

    onExit() {
        Application.exit();
    }
}


const form = new MyForm();
form.show();
Application.run();

ListView.addColumn

function ListView.addColumn(caption : String, width : Integer, alignment : AlignmentEnum)

Arguments

caption
The column caption
width
The width of the column in pixels
alignment
The column alignment (ListView.AlignLeft, ListView.AlignCenter, or ListView.AlignRight)

Returns

True if the column was properly added, false otherwise

Description

Adds a column to the list view control. The list view must be in Details mode in order for the column to be displayed. See setView() for more information.

ListView.addItem

function ListView.addItem(item : ListViewItem)

Arguments

item
The ListViewItem item to add to the ListView.

Description

Adds a ListViewItem item to the ListView.

ListView.clear

function ListView.clear()

Description

Deletes all list view items from the control, clearing it out. Columns are not removed.

ListView.deleteColumn

function ListView.deleteColumn(column_index : Integer)

Arguments

column_index
The zero-based column to delete.

Returns

True if the column was properly added, false otherwise

Description

Deletes a column from the list view control.

ListView.deleteItem

function ListView.deleteItem(item : ListViewItem)
function ListView.deleteItem(item_index : Integer)

Arguments

item
A list view item object
item_index
The zero-based index of the item to delete

Returns

True if the item was properly deleted, false otherwise

Description

Deletes an item from the list view. Either an item index or a list view item object may be specified in the parameter.

ListView.deselectAllItems

function ListView.deselectAllItems()

Description

Deselects all the items in the list view control

ListView.deselectItem

function ListView.deselectItem(item : ListViewItem)
function ListView.deselectItem(item_index : Integer)

Arguments

item
The list view item object to deselect
item_index
The zero-based index of the item to deselect

Description

Deselects the specified item or the item at the specified index.

ListView.findItem

function ListView.findItem(text : String, index : Integer) : ListViewItem

Arguments

text
The text of the item to find.
index
(Optional) The zero-based index of the item to start at. If this parameter is left blank or is -1, the find operation will always start with the first item in the ListView.

Returns

Returns the ListViewItem if it's found, and null if the item can't be found.

Description

Finds an item with the specified text and returns the ListViewItem that was found. If a ListViewItem with the specified text can't be found, the function returns null.

ListView.getItem

function ListView.getItem(item_index : Integer) : ListViewItem

Arguments

item_index
The zero-based index of the item to retrieve

Returns

A ListViewItem object. If the call failed, null is returned.

Description

Retrieves an item from the list view. In the parameter, either an item index or a list view item object may be specified.

ListView.getItemCount

function ListView.getItemCount() : Integer

Returns

The number of items in the list view control

Description

Returns the number of items in the list view control

ListView.getItems

function ListView.getItems() : Array(ListViewItem)

Returns

An Array of ListViewItem objects

Description

Returns an Array object containing all ListViewItem objects in the list view control

ListView.getLabelEdit

function ListView.getLabelEdit() : Boolean

Returns

true if item labels may be edited by the user, false otherwise

Description

Returns a boolean value indicated whether the list view item labels may be edited

ListView.getSelectedIndex

function ListView.getSelectedIndex(index : Integer) : Integer

Arguments

index
(Optional) The zero-based index of the item to start at. If this parameter is left blank or is -1, the find operation will always start with the first item in the list view control.

Returns

Returns the zero-based index of the first selected ListViewItem object in the list view control after the start index. If there are no selected items, the function returns -1.

Description

Returns the zero-based index of the first selected ListViewItem object in the list view control after the start index. If there are no selected items, the function returns -1.

ListView.getSelectedItem

function ListView.getSelectedItem(index : Integer) : ListViewItem

Arguments

index
(Optional) The zero-based index of the item to start at. If this parameter is left blank or is -1, the find operation will always start with the first item in the list view control.

Returns

A ListViewItem object, or null if no items are selected in the list view.

Description

Returns the first selected ListViewItem object in the list view control. If no objects are selected in the list view control, null is returned.

ListView.getSelectedItems

function ListView.getSelectedItems() : Array(ListViewItem)

Returns

An Array of ListViewItem objects

Description

Returns an Array object containing all selected ListViewItem objects in the list view control. If no objects are selected in the list view control, an empty array is returned.

ListView.getView

function ListView.getView() : ListViewModeEnum

Returns

One of the following values: ListView.LargeIcon, ListView.SmallIcon, ListView.Details, or ListView.List

Description

Returns the current view mode of the list view control. See setView() for more information.

ListView.insertItem

function ListView.insertItem(item : ListViewItem, index : Integer)

Arguments

item
The ListViewItem item to insert into the ListView.
index
The position of the new item.

Description

Inserts a ListViewItem item into the ListView at the specified position.

ListView.isItemSelected

function ListView.isItemSelected(item : ListViewItem) : Boolean

Arguments

index
The item that is being checked for selection.

Returns

Returns true if the item is selected, and false otherwise. If an error is encountered during the call, null is returned.

Description

Indicates whether or not the specified item is selected. If the item is selected, the function returns true. If the item is not selected, the function returns false.

ListView.selectItem

function ListView.selectItem(item : ListViewItem)
function ListView.selectItem(item_index : Integer)

Arguments

item
The list view item object to select
item_index
The zero-based index of the item to select

Description

Selects the specified item or the item at the specified index.

ListView.setLabelEdit

function ListView.setLabelEdit(allow_label_edit : Boolean)

Description

Invoking setLabelEdit allows the caller to determine whether label edits are generally allowed in the list view control. Passing true to the allow_label_edit parameter effectively makes the control read-only from the user's perspective.

ListView.setView

function ListView.setView(mode : ListViewModeEnum) : Boolean

Arguments

mode
One of the following values: ListView.LargeIcon, ListView.SmallIcon, ListView.Details, or ListView.List

Returns

True if the view mode was successfully set, false otherwise

Description

List view controls have several view modes which allow data to be represented in various ways on the screen. The modes are ListView.LargeIcon, ListView.SmallIcon, ListView.Details, and ListView.List. The ListView.LargeIcon and ListView.SmallIcon modes allow items with various icon sizes to be viewed in a window. The ListView.Details and ListView.List modes allow items to be viewed as a list, along with extra columns to displayed next to the main item. The ListView.Details mode, in contrast with the ListView.List mode, has column headers. To use the ListView.Details or ListView.List mode, the caller must first add columns to the control.

ListView.sortItems

function ListView.sortItems(column_index : Integer, ascending : Boolean)

Arguments

column_index
The zero-based column index used as a basis for the sort operation
ascending
(Optional) Specifying true directs the operation to sort the control ascending, false descending.

Description

Sorts the items in the list view. The column_index parameter specifies the column index to use in the sort. The second parameter, which is optional, specifies the sort order. If this parameter is not specified, an ascending sort order is assumed.

ListView.columnClick

Arguments

index
The index of the column that is clicked.

ListView.columnRightClick

Arguments

index
The index of the column that is clicked.

ListView.itemActivate

Arguments

item
The item that is activated.
index
The index of the item that is activated.

ListView.itemBeginLabelEdit

Arguments

item
The item that is beginning to be edited.
index
The index of the item that is beginning to be edited.

ListView.itemEndLabelEdit

Arguments

item
The item that is finished being edited.
index
The index of the item that is finished being edited.

ListView.itemRightClick

Arguments

item
The item that is clicked.
index
The index of the item that is clicked.

ListView.itemSelect

Arguments

item
The item that is selected.
index
The index of the item that is selected.

ListView.keyDown

Arguments

index
Index of the list item that has the focus.
keyCode
Key code of the key pressed.
altDown
True if the Alt key is pressed, false otherwise.
controlDown
True if the Control key is pressed, false otherwise.
shiftDown
True if the Shift key is pressed, false otherwise.