InsertListBoxString method (WinStudio scripts)
Applies To
IWSFormComponent interface, list source components
Definition
Inserts a new entry into a list and returns an integer indicating where the new entry was inserted.
Syntax
object.InsertListBoxString( integer, string )
Part | Description |
object | Required. A reference to a list source component object. |
integer | Required. A reference to a zero-based index number of the new entry's row. |
string | Required. The text to be inserted as the new list entry. |
Remarks
If the new list entry is inserted successfully, the return value is the same as the index row number you requested ( integer ). If the insertion is unsuccessful, the return value is -1.
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