Personal tools
From wiki.swiftlytilting.com
Jump to: navigation, search

WinBinder Manual/ListView

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

Actions

The following actions are possible with list views:

  • Create one or more titles to identify each column using <winterpostwiki>wb_set_text</winterpostwiki>().
  • Clear all column titles calling <winterpostwiki>wb_set_text</winterpostwiki>() with text equal to NULL and item as FALSE or blank.
  • Create one or more titles to identify each column using <winterpostwiki>wb_set_text</winterpostwiki>().
  • Clear all items by calling <winterpostwiki>wb_set_text</winterpostwiki>() with text equal to NULL and item as TRUE.
  • Create one or more rows with one or more cells each, using <winterpostwiki>wb_create_items</winterpostwiki>().
  • Set the width of one or more columns with <winterpostwiki>wb_set_size</winterpostwiki>().
  • Assign an icon to a selected cell with <winterpostwiki>wb_set_item_image</winterpostwiki>().
  • Select a row and get the index of the currently selected row with <winterpostwiki>wb_get_selected</winterpostwiki>().
  • Delete one or more rows with <winterpostwiki>wb_delete_items</winterpostwiki>().
  • Change the text of a row or selected cells using <winterpostwiki>wb_set_text</winterpostwiki>().
  • Retrieve the string value of a cell using <winterpostwiki>wb_get_text</winterpostwiki>().
  • Show or hide grid lines with <winterpostwiki>wb_set_style</winterpostwiki>() and the WBC_LINES style.

Using 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.

Example

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);

See also

Winbinder Projects