Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

List Control in the guise of a grid

0.00/5 (No votes)
21 Aug 2002 1  
This article shows how to make the listcontrol to act as a grid control.

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 ;-)

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