In these examples the listbox has the ID 1, and has 3 columns and 10 rows.
Before starting with a listbox its usually best to
reset it because HN can remember the final structure from when the project was previously run in Creator.
ListboxDeleteAll(1)
A listbox can also be set up in the
card's opening event so making it appear instantly.
When editing a card's script or its controls:
The opening event is the first item in the leftmost column of the listbox entitled "Card".
Any items listed after the card's opening event are all for for controls such as buttons fields etc,
Set a listbox to have 3 columns:
ListboxSetColumns(1,3)
Alternatively you could build a 3 column listbox having 10 rows using the
ListboxBuild command:
ListboxBuild(1,10,3)
- How can I set heading text?
ListboxSetHeading(1,1,'Title 1')
ListboxSetHeading(1,2,'Title 2')
ListboxSetHeading(1,3,'Title 3')
- How can I Insert a value into the second column?
So to set the listbox cell column 2 and row 9, to value 'hello' use:
ListboxSetCellValue(1,9,2,'hello')
- Can I run a command If the user double clicks on a row?
Your script can check for various listbox events using the function
ListboxEventFN(id):
For instance, this code checks if a cell was clicked. When a cell is clicked, it finds the cell coordinates and then calls a user-defined procedure to do something.
Local event,row,col
Put ListboxEventFN into event
If event=2 then
Put ListboxRowClickedFN(1) into row
Put ListboxColumnClickedFN(1) into col
Put ListboxCellValueFN(1,row,col) into txt
Call DoSomething(row,col,txt)
endif
Note, a listbox's script is only called in response to an event such as when the user clicks a cell, drops a file on it, etc.
Here are the event numbers and descriptions:
1 - Cell action either editable cell or checkbox clicked.
2 - Cell clicked.
3 - Drag reorded rows.
4 - Drag row.
5 - Drop drag.
6 - Drop file.
7 - Double click.
8 - Header pressed
9 - Cell key down.
10 - Cell got focus.
11 - Cell text change.
12 - Cell lost focus.
13 - Sort column.
The
ListboxSetColumns(id,ncols) changes the number of columns, for instance to 5, in this code:
ListboxSetColumns(1,5)
Note, if you want to add a row use the
ListboxAddRow(id,value) command.
It adds value into the first cell of the new row.
ListboxAddRow(1,'cell value')