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.
The following are some of the commonly used properties of the ListView control −
Alignment
Gets or sets the alignment of items in the control.
AutoArrange
Gets or sets whether icons are automatically kept arranged.
BackColor
Gets or sets the background color.
CheckBoxes
Gets or sets a value indicating whether a check box appears next to each item in the control.
CheckedIndices
Gets the indexes of the currently checked items in the control.
CheckedItems
Gets the currently checked items in the control.
Columns
Gets the collection of all column headers that appear in the control.
GridLines
Gets or sets a value indicating whether grid lines appear between the rows and columns containing the items and subitems in the control.
HeaderStyle
Gets or sets the column header style.
HideSelection
Gets or sets a value indicating whether the selected item in the control remains highlighted when the control loses focus.
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.
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.
InsertionMark
Gets an object used to indicate the expected drop location when an item is dragged within a ListView control.
Items
Gets a collection containing all items in the control.
LabelWrap
Gets or sets a value indicating whether item labels wrap when items are displayed in the control as icons.
LargeImageList
Gets or sets the ImageList to use when displaying items as large icons in the control.
MultiSelect
Gets or sets a value indicating whether multiple items can be selected.
RightToLeftLayout
Gets or sets a value indicating whether the control is laid out from right to left.
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.
SelectedIndices
Gets the indexes of the selected items in the control.
SelectedItems
Gets the items that are selected in the control.
ShowGroups
Gets or sets a value indicating whether items are displayed in groups.
ShowItemToolTips
Gets or sets a value indicating whether ToolTips are shown for the ListViewItem objects contained in theListView.
SmallImageList
Gets or sets the ImageList to use when displaying items as small icons in the control.
Sorting
Gets or sets the sort order for items in the control.
StateImageList
Gets or sets the ImageList associated with application-defined states in the control.
TopItem
Gets or sets the first visible item in the control.
View
Gets or sets how items are displayed in the control. This property has the following values:

LargeIcon − displays large items with a large 32 x 32 pixels icon.
SmallIcon − displays items with a small 16 x 16 pixels icon
List − displays small icons always in one column
Details − displays items in multiple columns with column headers and fields
Tile − displays items as full-size icons with item labels and sub-item information.  
VirtualListSize
Gets or sets the number of ListViewItem objects contained in the list when in virtual mode.
VirtualMode
Gets or sets a value indicating whether you have provided your own data-management operations for the ListView control.
The following are some of the commonly used methods of the ListView control −
Clear 
Removes all items from the ListView control.
ToString 
Returns a string containing the string representation of the control.
The following are some of the commonly used events of the ListView control −
ColumnClick
Occurs when a column header is clicked.
ItemCheck
Occurs when an item in the control is checked or unchecked. 
SelectedIndexChanged
Occurs when the selected index is changed.
TextChanged
Occurs when the Text property is changed.
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 −

    63 Lectures 
     4 hours 

 Frahaan Hussain

    103 Lectures 
     12 hours 

 Arnold Higuit

    60 Lectures 
     9.5 hours 

 Arnold Higuit

    97 Lectures 
     9 hours 

 Arnold Higuit
 Print
 Add Notes
 Bookmark this page