Listbox Control in VB.NET
ListBox Control is a rectangular box type structure which allows user to display list of items from which user can select one or more items at a time.
It also allows user to sort items of the list in particular order.
User can add new items, remove selected or all items from ListBox at run time or design time.
Properties of Listbox Control in VB.NET
| Property | Purpose | ||||||
MultiColumn |
It is used to specify weather ListBox supports multiple columns or not. It has Boolean value. Default value is false. |
||||||
ColumnWidth |
It is used to specify width of each column in MultiColumn ListBox. |
||||||
Items |
It represents collection of items contained in ListBox control. |
||||||
Sorted |
It is used to specify weather items of ListBox are sorted in alphabetical order or not. It has Boolean value. Default value is false. |
||||||
SelectionMode |
It is used to get or set SelectionMode of ListBox. It determines how user can select the Items of ListBox. It can have one of the following four options: |
||||||
ScrollAlwaysVisible |
It is used to specify weather Scroll Bars is always associated with ListBox or Not regardless of number of items present in ListBox. It has Boolean value. Default value is false. |
||||||
HorizontalExtent |
It is used to get or set width in pixel, by which a ListBox can scrolled horizontally. It works only when Horizontal Scrollbar Property is set to true. |
||||||
HorizontalScrollbar |
It is used to specify weather ListBox can have Horizontal Scroll Bar or Not, If Number of Items in ListBox are not accommodate in specified width. It has Boolean value. Default value is False. |
||||||
SelectedIndex |
It is used to get or set zero based index of the item currently selected in ListBox. |
||||||
SelectedItem |
It is used to get or set item currently selected in ListBox. |
||||||
SelectedItems |
It is used to get collection of multiple items currently selected in ListBox. |
||||||
SelectedIndices |
It is used to get collection of zero based indexes of all items currently selected in ListBox. |
||||||
Enable |
It is used to specify weather ListBox Control is enabled or not at runtime. It has Boolean value. Default value is true. |
||||||
Visible |
It is used to specify weather ListBox Control is visible or not at runtime. It has Boolean value. Default value is true. |
||||||
TabStop |
It is used to specify weather user can use TAB key to set focus on ListBox Control or not. It has Boolean value. Default value is true. |
||||||
Methods of Listbox Control in VB.NET
| Method | Purpose |
ClearSelected |
It is used to unselect all the items that are currently selected in ListBox. |
FindString |
It is used to find first occurrences of an item in the ListBox that partially match with string specified as an argument. If an item is found than it returns zero based index of that item, otherwise it returns -1. The search performed by this method is case insensitive. |
FindStringExact |
It is used to find first occurrences of an item in the ListBox that exactly match with string specified as an argument. If an item is found than it returns zero based index of that item, otherwise it returns -1. The search performed by this method is case insensitive. |
GetSelected |
It is used to determine weather an item whose index is passed as an argument is selected or not. It returns Boolean value. |
SetSelected |
It is used to select or deselect an item whose index is passed as an argument. |
Events of Listbox Control in VB.NET
| Event | Purpose |
SelectedIndexChanged |
It is the default event of ListBox Control. It fires each time a selected Item in the ListBox is changed. |
Methods of Item Collection of ListBox
| Method | Purpose |
Add |
It is used to add an item at the end of ListBox collection. |
Insert |
It is used to insert an item at specific index position. |
Clear |
It is used to remove all items from ListBox collection. |
CopyTo |
It is used to copy all the Items of ListBox into an array that is passed as an argument. It also accepts an index position as an argument to specify from which index position within array copy will start. |
Remove |
It is used to remove first occurrence of an item that matches with value passed as an argument. |
RemoveAt |
It is used to remove an item from specific index position in ListBox. |
Contains |
It is used to determine weather a ListBox’s Item Collection contains an item that is passed as an argument. It returns Boolean value. If an item is found then it returns true otherwise false. |
Properties of Item Collection of ListBox
| Property | Purpose |
Count |
It is used to get number of items available in ListBox’s Item Collection. |