ListView Basics - July 2000

If you download this tip please consider making a modest donation of a $1.00 or more.

I have noted lots of posted questions in various news groups requesting information about the ListView control. So I created a very small demo which I zipped and placed on my web site in June 2000. There have been a lot of 'downloads' of the demo so I decided to expand it and make it the tip-of-the-month.

The ListView was introduced with Windows 95 as the 'right' side of Explorer. It was made available with VB4 32-bit. It is now available in VB6 as the Microsoft Windows Common Controls 6.0 OCX. The demo uses that version so you will need a copy if you want to run the demo. I used the SP5 version but I think earlier VB 6 versions will work.

2002/10/22 - Added 'check all' and 'select all' buttons, add a 'results' form and made some minor changes to the VB code.

The Demo Program

I created a demo that uses many of the ListView's properties. The demo's window:

Listview Basics Demo

Overview

The ListView is defined with multi-select and check boxes enabled. I added 30 items to the ListView. Half use the Internet Explorer logo and half use a computer logo.

Some Properties

Property Comment
Checkboxes = True  show with check boxes
MultiSelect = True  allow multiple selection
HideSelection = False  keep selection when lost focus
FullRowSelect = True select the full row
GridLines = True show grid lines
Arrange = lvwAutoLeft arrange along left side

Click Header

Click a column header to demonstrate how to sort a ListView column.

Process Selected or Checked Items

Click button 'Process Selected or Checked Items' to display a list of the selected or checked items. For example:

Review the code sample connected to the 'Command2_Click' event to learn how to iterate through the ListItems collection. You could use similar logic to process selected or checked items.

Change View

Click button 'Change View' to cycle through the four display options [Icon, Small Icon, List, and Report]. A sample:

Changed ListView

Other Useful ListView Tips

Tip Month Year
Set ListView Column Widths Using SendMessage API March 2000
Sort Icon in ListView Header February 2002
Show a File's Associated Icon in a ListView April 2003

Recommended Site For More ListView Details

Brad Martinez [http://www.mvps.org/btmtz/listview/] has done a great job explaining how to use API's to extend the usefulness of the ListView control. You may want to pay a visit to his site.

The Demo Uses...

Module - Click for Details Description
modLocationLocationLocation.bas Save and restore the window location among other things.
TBRegistry.bas Read and Write to the Registry.
modConnectToWebSite.bas Connect to a URL, display this page.

Download VB Code

Click here to download the VB 6 Source Code [25k].

If you download this tip please consider making a modest donation of a $1.00 or more.
If you download this tip please consider making a modest donation of a $1.00 or more.

Previous Tip   Tip Index   Next Tip

Home

Updated 2010/01/03