A ListView is a control that displays data arranged as a rectangular grid of rows and columns. Each row is a selectable item. Each element in the row is called a cell.
Contents |
The following actions are possible with list views:
The function used to create rows and cells is <winterpostwiki>wb_create_items</winterpostwiki>(). This function can create one or more rows at once by passing an array of arrays as the items parameter. Each element of the second-level array is the value of a cell to be inserted. The function returns the index of the lastly inserted row.
Function <winterpostwiki>wb_set_text</winterpostwiki>() can be used to change the text of a single cell or row. Use the table below:
| text | Item | Subitem | What it does |
|---|---|---|---|
| string | integer | integer | Sets the text of the cell indexed by item (the row) and subitem (the column). |
| array of strings | integer | blank | Sets the text of all cells in the row indexed by item. A NULL element will skip a cell. |
| NULL | FALSE | blank | Clears all column titles |
| NULL | TRUE | blank | Clears all cells |
To retrieve the text of a cell, row or the whole ListView, use <winterpostwiki>wb_get_text</winterpostwiki>(). Use the following table:
| Item | Subitem | What it retrieves |
|---|---|---|
| integer | integer | The text of the cell indexed by item (the row) and subitem (the column). |
| integer | blank | An array containing the text of all cells in the row indexed by item. |
| blank | blank | If no cells are selected: a two-dimensional array containing the text of all cells in the control. The list will end when it reaches the first blank line. If one or more cells are selected: A two-dimensional array containing the text of the selected cells in the control. |
You may assign an image to a treeview cell using function <winterpostwiki>wb_set_item_image</winterpostwiki>(). The parameter item specifies the row index and subitem is the column index.
The code below shows how to create a list view and add some data to it.
// Create a ListView
$list = wb_create_control($mainwin, ListView, "", 5, 30, 540, 200, ID_ITEMLIST,
WBC_VISIBLE | WBC_ENABLED | WBC_SORT | WBC_LINES | WBC_CHECKBOXES);
// Set the column titles
wb_set_text($list, array(
array("File", 100),
array(null, 80),
array("Name", 140),
array("Update", 200),
));
// Create rows and columns
wb_create_items($list, array(
array("1,000", "Bob", "John", "Peter"),
array(0, "Sue", "Paul", "Mary"),
array("200", null, 300/2, pi()),
));
// Set listview images
wb_set_image($list, PATH_RES . "toolbar.bmp", GREEN, 32);
wb_set_item_image($list, 5, 0, 1);
wb_set_item_image($list, 2, 2, 3);