Home > DeveloperSection > Beginner > ListView Control in VB.Net

ListView Control in VB.Net


VB.Net VB.Net 
Ratings:
0 Comment(s)
 10617  View(s)
Rate this:

ListView Control in VB.Net

ListView control is a window that displays a collection of items. . In ListView you can list the items in list view, icon view, and detail view.

Drag and drop ListView control from toolbox on window Form.

ListView Control in VB.Net

Code:

Add Item in ListView.

Public Class Form9

 

    Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'you have to specify  which view you want to see

        ListView1.View = View.Details

 

        'Columns is added to the ListView

        ListView1.Columns.Add("EmpName", 70, HorizontalAlignment.Left)

        ListView1.Columns.Add("ID", 40, HorizontalAlignment.Left)

        ListView1.Columns.Add("WorkType", 90, HorizontalAlignment.Left)

       

        'item is added to the ListView

        Dim str(3) As String

        Dim lv As ListViewItem

        str(0) = "Yash"

        str(1) = "1"

        str(2) = "designing"

        lv = New ListViewItem(str)

        ListView1.Items.Add(lv)

 

        Dim str1(3) As String

        Dim lv1 As ListViewItem

        str1(0) = "Raj"

        str1(1) = "2"

        str1(2) = "Programming"

        lv1 = New ListViewItem(str1)

        ListView1.Items.Add(lv1)

 

    End Sub

End Class

Run the Project

ListView Control in VB.Net

 

ListView Control Properties

Anchor property

Anchor property is used to set position of ListView when stretching Form.

ListView Control in VB.Net

Set anchor property to Top, Bottom, Left, Right

ListView Control in VB.Net

When you set anchor (Top, Bottom, Left, Right) property then distance from corner will be same after stretching Form.

ListView Control in VB.Net

 

BackColor:

Change backcolor of  ListView through BackColor property of ListView.

 Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'change ListView backcolor

        ListView1.BackColor = Color.PowderBlue

 End Sub

ListView Control in VB.Net

ForeColor:

Change ForeColor of  ListView through ForeColor property of ListView.

 Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

         'change  Forecolor of ListView Item

        ListView1.ForeColor = Color.Red

 End Sub

 

When apllication run then ForeColor of ListView Item will change.

 

ListView Control in VB.Net


Don't want to miss updates? Please click the below button!

Follow MindStick