Click here to Skip to main content
Click here to Skip to main content

List Control in the guise of a grid

, 21 Aug 2002
Rate this:
Please Sign up or sign in to vote.
This article shows how to make the listcontrol to act as a grid control.
<!-- Article image -->

Introduction

This article presents an ActiveX Listview control developed using ATL/WTL which acts as a grid control with the facility to edit subitems, add/modify/delete rows. This is an owner drawn control, and displays the editable rows and read-only rows in different color. This control can be used in VB, IE, etc.

Features

The activex listview control implemented using WTL classes has the support for editing subitems and basic user navigation. To edit an editable subitem, double click on the item and after modification hit the enter key and you are done. The control also provides the interface to insert columns and rows from clients like VB or IE.

The rows can be added by calling the interface methods or by using the mouse. To add the row just right click on the control and select "add row". Here I have given provision to add two types of rows, editable and read only. The editable rows are red in color and the read only rows are in blue color. Before inserting the rows into the list control, the number of columns has to be specified as shown in the client program. Sample client is writted in VB as well as in HTML. Properties to set height, width and the position on the screen are supported.

Notes

This control is based on the Edit and SysListview32 controls in Windows. The control is an owner drawn control. To edit the subitems in the list control, I just display the edit control at that place and set its text to the text in that subitem and after hitting the Enter key I set that particular item of the list control with the new text. I have modified the SetObjectRects function to support the positioning and the height/width properties of the control. The itemdata is stored in the CArray class, since I was unable to store the data in the lparam of the LVITEM structure. If anybody can get rid of the array please put a mail to me Wink | ;-)

The activex control was built with Visual C++ 6.0 Enterprise Edition on Windows 2000 Professional edition. I have commented the code wherever I felt necessary. Thanks to Todd C. Wilson for providing the header file to optimize the code. it certainly helped in reducing the code. Read http://www.codeproject.com/tips/aggressiveoptimize.asp to reduce the code size.

Drop me a line when you find any bugs or if you have any comments / suggestions / improvement at all to this ActiveX listview control. Furthur improvements that can be done to this control is to make the columns datatype specific and also display combo box where ever appropriate to modify the data in the cell.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sharan Basappa
Team Leader
India India
He is a graduate, currently working as a Software Engineer in Bangalore, India. You can reach him at sharan34@yahoo.com

Comments and Discussions

 
QuestionCan the position of control be changed ? Pinmembermnsam19-Aug-10 3:57 
AnswerRe: Can the position of control be changed ? PinmemberSharan Basappa19-Aug-10 4:19 
GeneralRe: Can the position of control be changed ? Pinmembermnsam19-Aug-10 20:00 
GeneralRe: Can the position of control be changed ? PinmemberSharan Basappa20-Aug-10 1:10 
Questionhow the cycle throught the edit controls by using VK_TAB when the activeX is hosted in a HTML-document? Pinmemberstefanb2-Feb-05 2:46 
AnswerRe: i think i managed to get through... Pinmemberstefanb3-Feb-05 4:24 
QuestionChanging color of grid? PinmemberStratofortress5-Aug-03 23:24 
AnswerRe: Changing color of grid? PinmemberSharan2-Nov-03 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 22 Aug 2002
Article Copyright 2002 by Sharan Basappa
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid