Tip 42

How do I write code that uses ListView control to display list of records?

Ans: Create a Windows application and place three text boxes named empname, age, sal for writing name, age and salary of an employee. Place a button called ‘Add’ and a list view control on the form. On clicking ‘Add’ button information in all edit boxes should get added in the list view under appropriate column. Set the View property of list as Details. Click on the Columns property in the Property Window for list, add three columns to list in ColumnHeader Collection Editor and set their Text Properties as ‘Name’, ‘Age’, ‘Salary’ respectively. Then add following code in the Click Event handler of the ‘Add’ button.

Private Sub adddata_Click ( ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles adddata.Click

Dim litem As New ListViewItem( )
litem.Text = empname.Text
litem.SubItems.Add ( age.Text )
litem.SubItems.Add ( sal.Text )
list.Items.Add ( litem )

End Sub

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>