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

Customising the ListView Control
There are a large number of new features you can take advantage of with the ListView control. This sample gives a brief overview of all the things you can do to make your application stand out.

Customised ListView

UpdatedUpdated!
2 January 1999: Added a method to remove the buttons from the ListView header, and tidied up the code a little bit.

Download the LVPlay project files (44kb)

This sample requires the SSubTmr.DLL component. Make sure you have loaded and registered this before trying the LVPlay project.

The options which you can set depend on which version of the Common Controls DLL (COMCTL32.DLL) is available on the target machine. The most advanced features are only available if you have the version of COMCTL32.DLL installed with IE4.0. This DLL can also be downloaded separately from the Microsoft site. (Note you must register with MSDN to follow this link, but it is free!).
With all versions you can:

  • Implement a customised sorting procedure using a Callback function. The sample code includes a generic routine which allows you to sort correctly according by text, number and date in either ascending or descending order. This is a very powerful feature, the only slight disadvantage which arises when you use it is that the Visual Basic ListItem Indexes are not re-sorted so they no longer run in the order seen in the control. This isn't too much of a problem normally since the Index still refers to the correct item, its just that you can't use it to determine whereabouts the item is in the control. The source code shows some API techniques you can use to determine what order the items are actually in.

With version 4.70 (shipped with IE3.0+) you can:
  • Add Check Boxes to each ListView item (note that although this works, the check boxes are drawn too small unless you have version 4.71 of COMCTL32.DLL). You can set/get the check state for each item in code.
  • Set the control to automatically select items when the mouse moves over them (a feature called 'Track Select' which can be surprisingly irritating!)
  • Make items highlight as the mouse moves over them (hot tracking) (Good)
  • Customise the spacing between icons in Large Icons view
  • Show Grid Lines in the Detail view
  • Allow the Detail view Column Headers to be reordered, either in code or by Drag-Drop (Good)
  • Make the Detail view Column Headers highlight when the mouse moves over them (Good)
  • Extend the selection highlight so it covers the entire row in Detail view (Good)
  • Add icons to the Column Headers of the ListView (unfortunately the icons seem to adopt the wrong colour in their transparent parts, coloured the same colour as the list view background rather than the header background. Otherwise this is a great feature. I'm working on how to avoid this.)
  • Set the indentation of items in Detail View (Good)
  • Add icons to columns other than the first column of the Detail View (Excellent)

With version 4.71 (shipped with IE4.0+) you can:
  • Adjust the scroll bars so they display as flat scroll bars (as seen in Full Screen view of IE4.0 - Good)
  • Set all items to be Underlined (Why?!)
  • Set 'Working Areas' in the control. This allows you to divide the control into different areas and set which area a list item appears in. The intention of this is to physically separate out items which have different attributes. An example of how this could be used is to set up two Working Areas, and have read only files in the right hand area and normal files in the left hand area. Dragging a file from the right area to the left would then reset the read only flag, and vice-versa.
  • Change the background of the ListView to a bitmap (which is asynchronously downloaded - Excellent!)
  • Change the time it takes before an item is selected when Track Select is on (you need this if you intend to use Track Select because the default time is the Start Menu Popup time - which advanced users have been known to set very short! Actually, even worse is when you work for a company with a pile of hopeless hackers in the desktop support department, who make sure everybody's computer has a menu select time of 0.01 microseconds, resulting in major hangs and agro whilst trying to navigate your Start Menu when they've messed up the Network again...)

Download the source code, have fun, and make your application look better with very little effort!


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: 2 January 1999