- This topic explains about the properties of ListBox in vb programming.
- Here contains the list of properties that used in ListBox control in vb programming.
ListBox Control – Properties of ListBox in vb
- ListBox control in Visual Basic 6.0 is replaced is replaced by either Windows form ListBox control or CheckedListBox control in vb.net.
- In ListBox, The name of some properties, events, methods and constants are different when compared to Visual Basic 6.0.
- ListBox provides an interface to display a list of items
- User can select one or more items from the listBox.
- ListBox can be used to display multiple columns.
ListBox.Items property – Properties of ListBox in vb
- Get the items of the ListBox
- Syntax
|
1 |
'DeclarationPublic ReadOnly Property Items As ListBox.ObjectCollection |
- This property enables you to obtain a reference to the list of items that are currently stored in the ListBox.
- With this reference, you can add items, remove items, and obtain a count of the items in the collection.
- You can also manipulate the items of a ListBox by using the DataSource property.
1) To add items to the ListBox (Default Items) – Properties of ListBox in vb
|
1 2 |
ListBox1.Items.Add("FirstItem") ListBox1.Items.Add("FirstItem2") |
2) To add items to the ListBox (from TextBox) – Properties of ListBox in vb
|
1 |
ListBox1.Items.Add(TextBox1.Text) |
3) Count the no of items in the ListBox – Properties of ListBox in vb
|
1 |
TextBox1.Text = ListBox1.Items.Count |
4) Add items to the specified index of ListBox – Properties of ListBox in vb
|
1 2 3 |
ListBox1.Items.Insert(1, "Hello") ' 1-index 'or ListBox1.Items.Insert(1, TextBox1.Text) |
5) To clear ListBox items – Properties of ListBox in vb
|
1 |
ListBox1.Items.Clear() |
6) To get selected item of the ListBox – Properties of ListBox in vb
|
1 2 3 |
TextBox1.Text = ListBox1.Text 'or TextBox1.Text = ListBox1.SelectedItem |
7) Get selected items through index - Properties of ListBox in vb
|
1 2 3 |
TextBox1.Text = ListBox1.SelectedIndex 'or TextBox1.Text = ListBox1.Items.Item(2) |
8) To remove a selected item from the ListBox – Properties of ListBox in vb
|
1 |
ListBox1.Items.Remove(ListBox1.SelectedItem) |
9) Remove selected item using index – Properties of ListBox in vb
|
1 2 3 |
ListBox1.Items.RemoveAt(2) 'or ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) |






