Kixforms ListView



Kixforms - The ListView Object

By Shawn Tassie (Toronto, Canada)

Overview

A ListView is a control that allows you to quickly display tabular data. The list has four modes of operation:

• Large Icon - Displays items with large icons and your main text

• Small Icon - Displays items with small icons and your main text

• List - Displays items with your main text

• Report - Displays items with small icons, your main text, and any other subitems to be displayed in columns.

Although all four modes of operation have been exposed in the current release, icon support has not been enabled yet. Only Report mode will be immediately usefull and discussed in this paper.

The general logical layout of a list view looks like this:

[pic]

A list view is composed of columns and items. Items are composed of the main subject item and a collection of associated subitems (details) - one for each column defined. Item 0 can also be referred to as SubItem 0. Items are analagous to Rows in a spreadsheet, and SubItems are analagous to Cells … although the analogy is not perfect – it can be usefull to think of a list view in those terms.

Keyboard Interface

If there is a selected row, the arrow keys will move the selection up or down. PgUp and PgDn down have their usual meanings. If MultiSelect is enabled, holding down the shift key and using the up and down arrow results in multiple rows of data being selected. Holding down the CTRL key while using the arrow keys results in moving the focus bar (dotted rectangle) during a selection and is used to select non-adjacent items. Hitting the space bar while in this mode selects the item. Holding down shift while using PgUp or PgDn down is a convienent way to select large amounts of data.

Mouse Interface

Left click on a row moves the focus and the selection to that row. Left click on a column header automatically sorts the column in reverse alphabetical order (that is to say – reverse to how it is currently sorted). Placing the mouse cursor between column headers and left-click-drag allows one to dynamically drag and resize the column. Double click between column headers automatically resizes the header to fit the largest item or subitem in that column.Use the mouse and scrollbars to access columns that may be out of view.

Creating a List

The list view is accessed as a regular COM object and inherits most of the properties, methods and behaviors supported by all other Kixforms objects.

$List = $Form.ListView

This statement creates an initially empty list positioned in the top left corner of the form (0,0) with a width and height of approx. 200 pixels. These are arbitrary values and can be customized during contruction:

$List = $Form.ListView(reserved, left ,top, width, height)

or afterwards using the individual property settings:

$List = $Form.ListView

$ = 10

$List.Left = 10

$List.Width = 300

$List.Height = 300

The resulting pointer $List identifies the list view and should be used in subsequent calls.

Adding columns to the list

A newly constructed list is empty of any columns or items. The following methods and properties are used to add columns.

$ = $List.Columns.Add("Name",50,0)

Creates a new column called "Name" that is 50 pixels wide a left aligned. The first parameter to the Add method is the heading text that will appear inside the column header. The second parameter is the width (in pixels) of the column. And the last parameter is the text alignment of the column and is specified as 0=Right 1=Left and 2=Centered.

$Column = $List.Columns.Add

$Column.Text = "Name"

$Column.Width = 100

$Column.Alignment = 2 ; Centered

This example hangs on to the handle returned from the Columns.Add method and uses it to specify each column property seperately.

$List.Columns.Count = 10

Used to quickly and easily create many blank columns.

Adding items to the list

$Item = $List.Items.Add("John Doe")

Adds an item to the list at the next available index. Optional parameter is the text to display in the first column. Returns a handle to an item object.

$Item = $List.Items.Add

$Item.Text = "John Doe"

Adds a new item and uses its handle to specify individual item settings.

For $i = 1 to 100

$Item = $List.Items.Add

$Item.SubItems(0).Text = "John Doe"

$Item.SubItems(1).Text = "74 Maple Drive"

$Item.SubItems(2).Text = "905-555-1234"

Next

Adds 100 items to the list and initializes all three columns with data. Remember that each column has an associated SubItem entry in every Item. And note that these two statements:

$Item.Text = "John Doe"

$Item.SubItems(0).Text = "John Doe"

produce the same result. Both set column 0 of $Item to "John Doe". SubItem(0) of every item is really a backward link to the main subject item itself.

Setting data in the list

$List.Items(5).Text = "John Doe"

Sets the text value of item 5 to the specified string.

$List.Items(1).SubItems(2).Text = "New Address"

Sets the text value of Item 1 SubItem 2 to the specified string.

Getting data from the list

$Value = $List.Items(2).Text

Gets the text value from the item located at index 2.

$Value = $List.Items(0).SubItems(1).Text

Gets the first subitem value from the item located at index 0.

Removing data from the list

$List.Items(1).Remove

Removes the item at index location 1.

$List.FocusedItem.Remove

Removes the item that has the focus.

For Each $Item In $List.SelectedItems

$Item.Remove

Next

Removes all selected items

$List.SelectedItems.Clear

Removes all selected items.

Managing the selection

$Item = $List.FocusedItem

Gets the item in the control that currently has focus.

$Count = $List.SelectedItems.Count

Returns the number of selected items in the list.

For Each $Item In $List.SelectedItems

$Item.Selected = 0

Next

Enumerates every selected item then deselects it.

If $List.FocusedItem.Selected

; Do something …

EndIf

This is a good way to structure the OnClick event logic for the list view. Because the FocusedItem may not necessary be one of the selected items – might check for that using the Selected property.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery