GetListBoxCurSel method (WinStudio scripts)
Applies To
IWSFormComponent interface, List component type objects
Definition
Returns the index number of the currently selected item in a List type component. Read-only.
Syntax
object.GetListBoxCurSel( )
Part | Description |
object | Required. A reference to a List component type object. |
Remarks
The return value is an integer indicating the index number of the currently selected item in a list box component. If no entry is selected, the return value is -1. Index numbers are zero-based.
Example
Sub Main()
Dim oListBox As IWSFormComponent
Dim iCurrentRow As Integer
Dim iCounter As Integer
Dim strListBox As String
Dim bSuccess As Boolean
Dim iReturn As Integer
Dim iRow As Integer
oListBox = ThisForm.Components("list1")
'Check to verify that a list item is selected.
'If not, display a message and exit.
iCurrentRow = oListBox.GetListBoxCurSel()
If iCurrentRow = -1 Then
Application.ShowMessage("No list item selected!")
Exit Sub
End If
'Display list box properties.
Application.ShowMessage("Number of items: " & oListBox.GetListBoxCount().ToString() _
& vbLf & "Current selection: " & (iCurrentRow + 1).ToString() & vbLf & _
"Text: " & oListBox.GetListBoxText(iCurrentRow))
'Display contents of list box.
strListBox = ""
For iCounter = 0 To oListBox.GetListBoxCount() - 1
strListBox = strListBox & (iCounter + 1).ToString() & " " & _
oListBox.GetListBoxText(iCounter) & vbLf
Next iCounter
Application.ShowMessage("The following are the currently defined events:" _
& vbLf & strListBox)
'Set list box to second entry.
iRow = 1
bSuccess = oListBox.SetListBoxCurSel(iRow)
'Insert new items at the second position.
iReturn = oListBox.InsertListBoxString(iRow, "New Row Entry 1")
iReturn = oListBox.InsertListBoxString(iRow, "New Row Entry 2")
'Display contents of list box.
strListBox = ""
For iCounter = 0 To oListBox.GetListBoxCount() - 1
strListBox = strListBox & (iCounter + 1).ToString() & " " & _
oListBox.GetListBoxText(iCounter) & vbLf
Next iCounter
Application.ShowMessage("Current list: " & vbLf & strListBox)
'Delete the rows just added.
oListBox.DeleteListBoxString(iRow + 1)
oListBox.DeleteListBoxString(iRow)
'Display contents of list box.
strListBox = ""
For iCounter = 0 To oListBox.GetListBoxCount() - 1
strListBox = strListBox & (iCounter + 1).ToString() & " " & _
oListBox.GetListBoxText(iCounter) & vbLf
Next iCounter
Application.ShowMessage("Current list: " & vbLf & strListBox)
End Sub