<!-- Article image -->
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.
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.
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.