The document discusses controls in Visual Basic like ListBox and CheckedListBox. It provides code examples for adding items to and retrieving selected items from the controls. Events are associated with the controls to handle user interactions like copying items between ListBoxes or getting selected items. The last part replaces the ListBox with a CheckedListBox and modifies the code to retrieve all selected items in a message box.
30. Error
No selection made mean ListBox1.SelectedIndex = -1 , this
value will produce an Error.
ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text
ListBox1.Items
White
Red
Black
yellow
ListBox1.SelectedIndex
0
1
2
3
38. Code illustration
Dim X As New System.Text.StringBuilder
For I = 0 To 3
X.Append(CheckedListBox1.Items(I))
X.Append(" ")
Next
MessageBox.Show(X.ToString())
System.Text NameSpace
StringBuilder Class
Append(item) Append (String)
ToString Method
39. Dim X As New System.Text.StringBuilder
For Each item In CheckedListBox1.Items
X.Append(item) ‘items
X.Append(" ") ‘spaces
Next
MessageBox.Show(X.ToString())
System.Text NameSpace
StringBuilder Class
Items Property
Append(item) Append (String)
ToString Method
Modify Last Code
40. NameSpace
container for a set of identifiers
(names)
Class
A set of instance information for a
real content.
Property Property
Append (String)
Appends a copy of the specified
string to this instance.
ToString
(Method)
convert the StringBuilder object to a
String object before you can pass
the string represented by the
StringBuilder object to the user
interface.
Code illustration