HyperNext Studio > Getting Started

How can I use Listbox?

(1/1)

LinesOfCodes:
I want to use a Listbox but I don't know what command I have to type to use it the way I want.
I want to know:

* How can I set heading text?
* How can I Insert a value into the second column?
* Can I run a command If the user double clicks on a row?
* If HyperNext can't do the third one, then Can HyperNext script get the number of the row in the list that the user is selected?
* How to add more columns
That's all I want to know.

LinesOfCodes:
I try reading "Language Reference 401.pdf" on the download page.
Now I know how to add a value into the second column by using the "ListboxSetCellValue bid, row, col, val" command

* bid: Field ID
* row: What row you want to insert a value
* col: What column you want to insert a value
* val: Message you want to be insert
Set Heading text by using the "ListboxSetHeading bid, col, val"

* bid: Field ID
* col: Column you want to set the heading
* val: Text you want to set
Get the currently selected row by using the "ListboxIndexFN(1)" command
usage: Put ListboxIndexFN(1) into num

That's all I know for Today.

Malkom:

--- Quote from: LinesOfCodes on September 27, 2020, 02:56:30 AM ---I try reading "Language Reference 401.pdf" on the download page.
Now I know how to add a value into the second column by using the "ListboxSetCellValue bid, row, col, val" command

* bid: Field ID
* row: What row you want to insert a value
* col: What column you want to insert a value
* val: Message you want to be insert
Set Heading text by using the "ListboxSetHeading bid, col, val"

* bid: Field ID
* col: Column you want to set the heading
* val: Text you want to set
Get the currently selected row by using the "ListboxIndexFN(1)" command
usage: Put ListboxIndexFN(1) into num

That's all I know for Today.

--- End quote ---

Thank you for partially answering your own questions and so helping others :)

I'll add some example code in the post below.



Malkom:
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.


--- Code: ---ListboxDeleteAll(1)

--- End code ---

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:

--- Code: ---ListboxSetColumns(1,3)

--- End code ---

Alternatively you could build a 3 column listbox having 10 rows using the ListboxBuild command:

--- Code: ---ListboxBuild(1,10,3)

--- End code ---





--- Quote from: LinesOfCodes on September 26, 2020, 06:44:21 AM ---
* How can I set heading text?
--- End quote ---


--- Code: ---ListboxSetHeading(1,1,'Title 1')
ListboxSetHeading(1,2,'Title 2')
ListboxSetHeading(1,3,'Title 3')

--- End code ---




--- Quote from: LinesOfCodes on September 26, 2020, 06:44:21 AM ---
* How can I Insert a value into the second column?
--- End quote ---

So to set the listbox cell column 2 and row 9, to value 'hello' use:

--- Code: ---ListboxSetCellValue(1,9,2,'hello')

--- End code ---




--- Quote from: LinesOfCodes on September 26, 2020, 06:44:21 AM ---
* Can I run a command If the user double clicks on a row?
--- End quote ---

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.

--- Code: ---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

--- End code ---

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.





--- Quote from: LinesOfCodes on September 26, 2020, 06:44:21 AM ---
* How to add more columns
--- End quote ---

The ListboxSetColumns(id,ncols) changes the number of columns, for instance to 5, in this code:

--- Code: ---ListboxSetColumns(1,5)

--- End code ---

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.

--- Code: ---ListboxAddRow(1,'cell value')

--- End code ---

Navigation

[0] Message Index

Go to full version