The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
2 Common Controls Library &nbsp

Using a vbAccelerator ImageList or System ImageList with the Microsoft ListView Control

I said it couldn't be done - but Tom Esh proved me wrong!


ListView Browsing the System ImageList


Download Code
Download Tom Esh's System ImageList Viewer sample (4kb)
Download Tom Esh's FileListView sample (8kb)
Download the vbAccelerator classes for attaching an External ImageList to the MS ListView (34kb)

&nbsp Before you Begin &nbsp
&nbsp The vbAccelerator sample requires the SSubTmr.DLL. Please make sure you have downloaded and registered this control before trying the project. &nbsp

Overview
The Microsoft Common Controls work with the ImageList provided with the controls, but what if you want to use an external ImageList with better facilities, or, particularly, if you want to use a System ImageList with these components?

Previously on vbAccelerator I said this couldn't be done, however, thanks to Tom Esh for proving me wrong! By using the native API for the ListView, you can assign a new ImageList and then use the API to set the Image index for the icon for each ListItem. It is possible you can use similar techniques in the TreeView, TabStrip and other controls too. Found out how to do it? Mail me!

These techniques work in VB5 and VB6, although the download code only includes VB5 projects.


The ListView and External ImageLists
The steps required to make a VB ListView use an External ImageList are as follows:
  • Ensure that the ListView control is set to use Shared ImageLists (i.e. it will not destroy the ImageList when closed)
  • Assign a standard ImageList to the control with one image in (only required for VB6)
  • Use the LVM_SETIMAGELIST message to change the ImageList handle to the external ImageList. Here, if you wish, you can conserve system resources by deleting the ImageList associated with the MS ImageList control.
  • When adding an item, add it with Image index 1, and then use the LVM_SETITEM message to modify the Image index.
  • Whenever VB tries to reset the ImageList handle, ensure that the correct handle is replaced again. This appears to only occur when you change the View property of the ListView, however you can achieve a complete workaround by subclassing for the LVM_SETIMAGELIST message sent to the control and consuming it.
These steps are demonstrated in the download samples.



TopBack to top

Source Code - What We're About!Back to Source Code

&nbsp

AboutContributeSend FeedbackPrivacy

Copyright 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 9 August 1999