ListView (list view) controls are used to display items graphically, and you can use 4 different views. This control allows you to make a column with or without column headers and to display accompanying icons and text. The icon for the ListView control in the Toolbox is as shown in the figure:
You can use the ListView control to organize list entries called ListItem objects into one of the following 4 different views: Large (standard) icons, small icons, lists, reports.
1. Change views with View property
To change the view, you can use the View property. The following code sets the View property to report view, where internal constant view.largeicon is used, and the control is named "ListView1".
Listview1.view=view.largeicon
Use the View property to enable end users to dynamically change the view
2.InsertItem method
Adds a ListItem object to the ListItems collection of the ListView control and returns a reference to the newly created object. Applies to the ListItem object, the ListItem collection, and the syntax is:
Listviewname.insertitem (index as integer,text as string,imageindex as Integer,subitems () as String)
The syntax for the InsertItem method includes the following sections:
(1) Listviewname: Required. An object expression whose value is a listitems set;
(2) Index: Required. Specifies where to insert the ListItem integer. If no index is specified, the ListItem is added to the end of the ListItems collection;
(3) Text: Required. Specifies the title of the ListItem to be added;
(4) ImageIndex: Optional. This integer setting selects the icon to display from the ImageList control when the ListView control is set to the icon view;
(5) SubItems (): Optional. An array that is used to set the column headers when the ListView control is a report view.
Note: You must first initialize the ImageIndex property before setting it. There are two kinds of initialization methods: At design time, using the ListView control property page initialization, or at run time, using the following code to initialize:
Listview1.largeimagelist=imagelist1 ' Suppose ImageList for ImageList1
Listview1.smallimagelist=imagelist2
If the list has not been sorted, you can use the index parameter to insert the ListItem object to any location. If the list is sorted, the index argument is ignored and the ListItem object is inserted in the appropriate location according to the sort order.
If index is not provided, the ListItem object is added with an index equal to the number of ListItem objects in the collection plus 1.