VB.NET ListView Control
The ListView Controls are used to display a collection of items in the Windows Forms. It uses one of the view lists, such as LargeIcon, SmallIcon, Details, List, and Tile. Furthermore, the ListView allows the user to add or remove icons from the ListView Control.
Let’s create a ListView control in the VB.NET Windows form by using the following steps.
Step 1: We have to find the ListView control from the toolbox and then drag and drop the ListView control onto the window form, as shown below.
Step 2: Once the ListView is added to the form, we can set various properties of the List by clicking on the ListView control.
Properties of the ListView Control
There are following properties of ListView control.
Properties | Description |
---|---|
Alignment | The Alignment property is used to set the alignment for the item in the ListvVew Control. |
Activation | The Activation property is used to get or set a user-requested action to activate an item. |
CheckBoxes | The CheckBoxes property sets a value to display the checkbox that appears next to each item in the list view control. |
Columns | The Columns property is used to display the collection of columns header in the ListView Control. |
CheckIndices | The CheckIndices property is used to get all checked items in the ListView Control. |
GridLines | The GridLines Property is used to display the gridlines between the rows and columns that contain the items and subitems in the ListView Control. |
Items | It is used to collect the collection of the items that are in the ListView Control. |
LargeImageList | It is used to set or get ImageList to display it as a large icon in the ListView Control. |
HeaderStyle | It is used to set or get the column header style in the ListView control. |
MultiSelect | The MultiSelect property is used to set a value that allows selecting more than items in the ListView control. |
SelectedItems | It is used to obtain all selected items in the ListView control. |
ShowGroups | The ShowGroups property set a value that represents whether the ListView items are displayed in groups. |
SmallImageList | It is used to set or get ImageList to display the image as a small icon in the ListView control. |
TopItem | The TopItem property is used to set or get the first item in control. |
View | The View property is used to set the items displayed in the List view. The View property has the following values: SmallIcon: It is used to display small size icons. List: It is used to display items in a list, and it only shows captions. LargeIcon: It is used to display large size icons. Report: It is used to display items and its sub-items. |
Methods of the ListView Control
Method | Description |
---|---|
ArrangeIcons() | The ArrangeIcons method is used to arrange all the items displayed as icons in the ListView control. |
FindItemWithText() | It is used to search the first ListViewItem that started with the given text value. |
GetItemAt() | The GetItemAt method is used to get an item at the specified location of the ListView control. |
Clear() | The Clear method is used to clear all the items and columns from the ListView control. |
Sort() | The Sort method is used to sort items of the ListView. |
Events of the ListView Control
There are following events of the ListView control.
Events | Description |
---|---|
ItemActivate | The ItemActivate event occurred when an item activated in the ListView control. |
ItemChecked | The ItemChecked event is found in the ListView control when the checked state of an item changes. |
TextChanged | The TextChanged event is found in the ListView control when the property of the text changes. |
ItemCheck | When the status of a check item changes, the ItemCheck event is found in the list view control. |
AfterLabelEditEvent | It occurs when the user in the ListView control edits the label for an item. |
Let’s create a program to insert the records in the ListView control of the VB.NET Windows form.
List_View.vb
Output:
Now, we fill all the details of the Student that is asked in the Form.
Now, click on the Add New Entry button. It displays the record in the ListView control or in Student details table, as shown below.
Similarly, we have added the following student details in the form.