Escolar Documentos
Profissional Documentos
Cultura Documentos
Table of Contents:
Give the ListView control a facelift
with indentation and background images ............................................................................4
Drag and drop items from one ListView to another ............................................................8
Use a callback function to perform custom sorting
in a ListView control ...............................................................................................................11
Solving item-retrieval problems when sorting a
ListView with API callbacks..................................................................................................15
Effectively using the ImageList and ListView
controls in .NET .......................................................................................................................16
Additional Information:
Readers Choice PDF Series, Mastering Microsoft Visual Basic Controls:
ListView indentation, background shading, custom sorting, and more
(ISBN-1-58205-150-x) is published by Element K Journals, a division of
Element K Press, 500 Canal View Blvd., Rochester, N.Y., 14623.
Customer Relations
U.S. toll-free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .(800) 223-8720
Canada toll-free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .(877) 203-5248
Outside the U.S. and Canada . . . . . . . . . . . . . . . . . . . . . .(585) 240-7301
Customer Relations fax . . . . . . . . . . . . . . . . . . . . . . . . . . .(585) 292-4392
Editorial
Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sheila Davis
Associate Publisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Michelle Rogers
Managing Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mike Jones
Copy Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jeff Hotchkiss
Leesa Israel
Contributing Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . G. H. Cloutier
Cover Design and Content Designer . . . . . . . . . . . . . . . Melissa Ribaudo
Graphic Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Alicia Natale
Price
Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . $14.95
Copyright
Please be aware of our copyright policy. Questions or requests for
permission to copy or republish any content may be directed to:
contentreuse@elementk.com.
2004 Element K Journals, a division of Element K Press LLC (Element
K). All rights reserved except for the right to view this PDF using a
Web browser and to make private, noncommercial use hereof. PDF
content may be printed by the purchaser, but may not be duplicated and
distributed. Element K and the Element K logo are trademarks of Element
K LLC. The content published in this PDF (Content) is the property of
Element K or its affiliates or third party licensors and is protected by
copyright law in the U.S. and elsewhere. This means that the right to copy
and publish the Content is reserved. Content may not be copied in whole
or in part or further distributed in any form or medium without the express
written permission of Element K.
All product names or services identified throughout this PDF are trademarks or registered trademarks of their respective companies.
Multi-user options are available
To request information about multi-user options please call Brian McKeon
at (585) 292-4363.
Doreen M. Bieryla
Publisher, Element K Journals
Editor Bio:
Sheila is the editor of Inside Microsoft Visual Basic and Active Server Developers Journal. She has
over 12 years programming experience starting with Fortran and VB 3. In addition to programming, shes also been a software trainer, developed user documentation and training manuals,
and was a technical editor for the Visual Basic 6 Bible from John Wiley & Sons. In her spare time,
shes a floor mat for her 9-year-old daughter.
Well begin with a look at why and how the ListView control, as opposed to the TreeView or any
other control, is the best solution to this problem. Next, well develop a sample application that
goes a long way to replicating the user-interface in Outlook Express and other similar programs.
As you can see from Figure A, our sample will support indentation as well as ledger-style alternate-row highlighting through the judicious use of a background image.
Why a ListView?
The first question to answer is why wed want to customize a ListView control to serve our interface needs. Wouldnt a TreeView control work just as well? Or a custom hybrid we might write
ourselves? Though they might work as well, neither of the alternatives would be anywhere near
as easy to implement. Writing your own custom control would be an enormous and arduous task,
so thats out. In the end, the only viable alternative is a cosmetically altered ListView control.
The reason its easier to tackle modifying the ListView to act a little bit more like a TreeView than
vice versa comes down to the matter of columns. To give a TreeView control columns that users
can click, resize, and drag involves much more API manipulation than simply adding the ability to indent items in a
ListView. Thats because youd be dealing not only with
the ColumnHeaders collection and all of its constituent ColumnHeader objects, but youd also have to manage the relationship between these objects and a TreeView control entirely
through the API.