ListIndex(listboxName As String) As Integer

 

Gets the selected item number of listbox listboxName.

 

 

Parameters:

 

Name

Type

Value

Description

listboxName

String

name of control

ScreenFieldName of the listbox to set the number of columns.

Ctrl+Click onto a listbox to retrieve its listboxName

(= ScreenFieldName).

 

Returns:

 

Type

Value

Description

Integer

0 - n

The selected item number.

The index is zero-based.

If no item is selected, ListIndex returns -1.

If the ListBox is in multiple-row selection mode, then the number of the lowest selected row is returned.

For example, if rows 1, 3, and 4 are selected, ListIndex returns 1.

Integer

-1

No item is selected

Integer

-2

An error occurred. The listbox could not be found.

Integer

-3

An unknown error occurred.

 

Available in:

 

WindowMain

WindowLink

YES

YES

 

Used in:

 

XojoScript Name

GUID

Delete selected item and price in finances

35299AF9-97D6-45CD-9014-7460F8396199

Delete selected price from eventlist

813368EF-BD00-4341-BF44-AB606CC49FEE

Show selected event pricelist details

9ACFE85C-A75D-468A-B429-98F0D9C56862

Delete seminar participation payment

FBE87F41-596E-4C04-BB74-1B9A8FA21FEF

 

Hint: You can find references to XojoScripts which make use of this function by sending the following SQL statement to the database:

Select id,GUID, ScriptName,ScriptCode from im_scripts where ScriptCode Like '%ListIndex%'

 

 

Example 1 XojoScript:

 

// Get Index of selected record in listbox

Dim idx As Integer = ListIndex("imLB_evt_List3")

 

// Skip if idx is -1, then there is no selection

If idx >= 0 Then

 

// Retrieve listbox text and store its records into an array

Dim arrLBRecs(-1) As String = Split(GetText("imLB_evt_List3"),"{*REC*}")

 

// Retrieve selected record

Dim rec As String = arrLBRecs(idx)

 

// store fields of selected record into an array

Dim arrRecFlds(-1) As String = Split(rec,"{*FLD*}")

 

// Write each field out to textfields on screen

SetText("imTF_evt_PriceCode",arrRecFlds(0))

SetText("imTF_evt_Price",arrRecFlds(1))

SetText("imTF_evt_PriceEuro",arrRecFlds(2))

SetText("imTF_evt_TextD",arrRecFlds(3))

SetText("imTF_evt_TextE",arrRecFlds(4))

SetText("imTF_evt_TextF",arrRecFlds(5))

 

End If

 

 

Example 2 XojoScript:

 

// WindowLink, imSB_lnk_p02_Delete, Delete selected seminar participation payment

Dim lb As String = "imLB_lnk_p01_PaymentList"

ListRemoveRow(lb,ListIndex(lb))

 

// Recalc Total Payments

CalcTotal

 

// *********************************************

Sub CalcTotal()

Dim lbHandle As Integer = ListGetHandle("imLB_lnk_p01_PaymentList")

Dim numRows As Integer = ListCount(lbHandle)

Dim totalPaid As Double = 0.0

 

If numRows > 0 Then

For i As Integer = 0 to numRows-1

totalPaid = totalPaid + Val(ListGetCell(lbHandle,i,2))

Next

End IF

SetText("imTF_lnk_p01_TotalPaid",Format(totalPaid,"-#####0.00"))

 

End Sub