- VB.Net Basic Tutorial
- VB.Net - Home
- VB.Net - Overview
- VB.Net - Environment Setup
- VB.Net - Program Structure
- VB.Net - Basic Syntax
- VB.Net - Data Types
- VB.Net - Variables
- VB.Net - Constants
- VB.Net - Modifiers
- VB.Net - Statements
- VB.Net - Directives
- VB.Net - Operators
- VB.Net - Decision Making
- VB.Net - Loops
- VB.Net - Strings
- VB.Net - Date & Time
- VB.Net - Arrays
- VB.Net - Collections
- VB.Net - Functions
- VB.Net - Subs
- VB.Net - Classes & Objects
- VB.Net - Exception Handling
- VB.Net - File Handling
- VB.Net - Basic Controls
- VB.Net - Dialog Boxes
- VB.Net - Advanced Forms
- VB.Net - Event Handling
- VB.Net Advanced Tutorial
- VB.Net - Regular Expressions
- VB.Net - Database Access
- VB.Net - Excel Sheet
- VB.Net - Send Email
- VB.Net - XML Processing
- VB.Net - Web Programming
- VB.Net Useful Resources
- VB.Net - Quick Guide
- VB.Net - Useful Resources
- VB.Net - Discussion
VB.Net - ListView Control
The ListView control is used to display a list of items. Along with the TreeView control, it allows you to create a Windows Explorer like interface.
Let's click on a ListView control from the Toolbox and place it on the form.
The ListView control displays a list of items along with icons. The Item property of the ListView control allows you to add and remove items from it. The SelectedItem property contains a collection of the selected items. The MultiSelect property allows you to set select more than one item in the list view. The CheckBoxes property allows you to set check boxes next to the items.
Properties of the ListView Control
The following are some of the commonly used properties of the ListView control −
Sr.No | Property & Description |
---|---|
1 | Alignment Gets or sets the alignment of items in the control. |
2 | AutoArrange Gets or sets whether icons are automatically kept arranged. |
3 | BackColor Gets or sets the background color. |
4 | CheckBoxes Gets or sets a value indicating whether a check box appears next to each item in the control. |
5 | CheckedIndices Gets the indexes of the currently checked items in the control. |
6 | CheckedItems Gets the currently checked items in the control. |
7 | Columns Gets the collection of all column headers that appear in the control. |
8 | GridLines Gets or sets a value indicating whether grid lines appear between the rows and columns containing the items and subitems in the control. |
9 | HeaderStyle Gets or sets the column header style. |
10 | HideSelection Gets or sets a value indicating whether the selected item in the control remains highlighted when the control loses focus. |
11 | HotTracking Gets or sets a value indicating whether the text of an item or subitem has the appearance of a hyperlink when the mouse pointer passes over it. |
12 | HoverSelection Gets or sets a value indicating whether an item is automatically selected when the mouse pointer remains over the item for a few seconds. |
13 | InsertionMark Gets an object used to indicate the expected drop location when an item is dragged within a ListView control. |
14 | Items Gets a collection containing all items in the control. |
15 | LabelWrap Gets or sets a value indicating whether item labels wrap when items are displayed in the control as icons. |
16 | LargeImageList Gets or sets the ImageList to use when displaying items as large icons in the control. |
17 | MultiSelect Gets or sets a value indicating whether multiple items can be selected. |
18 | RightToLeftLayout Gets or sets a value indicating whether the control is laid out from right to left. |
19 | Scrollable Gets or sets a value indicating whether a scroll bar is added to the control when there is not enough room to display all items. |
20 | SelectedIndices Gets the indexes of the selected items in the control. |
21 | SelectedItems Gets the items that are selected in the control. |
22 | ShowGroups Gets or sets a value indicating whether items are displayed in groups. |
23 | ShowItemToolTips Gets or sets a value indicating whether ToolTips are shown for the ListViewItem objects contained in theListView. |
24 | SmallImageList Gets or sets the ImageList to use when displaying items as small icons in the control. |
25 | Sorting Gets or sets the sort order for items in the control. |
26 | StateImageList Gets or sets the ImageList associated with application-defined states in the control. |
27 | TopItem Gets or sets the first visible item in the control. |
28 | View Gets or sets how items are displayed in the control. This property has the following values:
|
29 | VirtualListSize Gets or sets the number of ListViewItem objects contained in the list when in virtual mode. |
30 | VirtualMode Gets or sets a value indicating whether you have provided your own data-management operations for the ListView control. |
Methods of the ListView Control
The following are some of the commonly used methods of the ListView control −
Sr.No. | Method Name & Description |
---|---|
1 |
Clear Removes all items from the ListView control. |
1 |
ToString Returns a string containing the string representation of the control. |
Events of the ListView Control
The following are some of the commonly used events of the ListView control −
Sr.No. | Event & Description |
---|---|
1 | ColumnClick Occurs when a column header is clicked. |
2 | ItemCheck Occurs when an item in the control is checked or unchecked. |
3 | SelectedIndexChanged Occurs when the selected index is changed. |
4 | TextChanged Occurs when the Text property is changed. |
Example
In this example, let us create a list view at runtime. Let's double click on the Form and put the follow code in the opened window.
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'create a new ListView Dim ListView1 As ListView ListView1 = New ListView() ListView1.Location = New Point(10, 10) ListView1.Size = New Size(150, 150) Me.Controls.Add(ListView1) 'Creating the list items Dim ListItem1 As ListViewItem ListItem1 = ListView1.Items.Add("Item 1") Dim ListItem2 As ListViewItem ListItem2 = ListView1.Items.Add("Item 2") Dim ListItem3 As ListViewItem ListItem3 = ListView1.Items.Add("Item 3") Dim ListItem4 As ListViewItem ListItem4 = ListView1.Items.Add("Item 4") 'set the view property ListView1.View = View.SmallIcon ' Set the caption bar text of the form. Me.Text = "tutorialspoint.com" End Sub End Class
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window −