Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC

SuperGrid - Yet Another listview control

Rate me:
Please Sign up or sign in to vote.
4.77/5 (98 votes)
8 Dec 1999CPOL3 min read 1M   11.4K   345   192
A combination list control and tree control with checkbox capability

Sample Image

Okay yet another full blown ownerdraw listview control with a tree like thing in the first column.

What´s new:

  • subitems now supports images
  • improved sorting
  • bugfixes reported by you.

please see the history section in the SuperGridCtrl.cpp file for further reading.

Features:

The listview control has support for editing subitems and basic user navigation. To edit an item hit the Enter key to start editing, when done editing, hit the Enter Key again. The listview control also has support for sorting items, drag and drop, basic scroll, autoscroll and autoexpand when dragging an item over another item. The listview control supports Insert/Delete items and you can use the +,-,* keys to expand/collapse items. The listview control does NOT support header drag/drop operations. Thanks for all them positive emails I have recived. If you have any suggestions to some future version let me know.

Note:

The class CSuperGridCtrl is derived from CListCtrl and it has a nested class called CTreeItem. The CTreeItem represents a node in a linked list. Each CTreeItem has a CObList representing its children and a few data members telling you the current status on the node e.g expanded, haschildren etc. Each listview item has a pointer to the CTreeItem(stored in the lParam of course). The CTreeItem has an associated class called CItemInfo. The CItemInfo class represents the data in the listview. This class is just a wrapper for the CStringArray, each item in the array represents a subitem. You may have to modify this class to suit your logical data-representation in the listview. In each CItemInfo you may associate a controltype: default controltype is an edit-control. In the source code you will find an example on how to associate a combobox control to a specific CItemInfo and how to initalize the combobox with default values.

Another standard control which is implicit in the listview control are the checkbox-control, by using the LVS_EX_CHECKBOXES style you will have this control for free, nothing new here....but in the CItemInfo class you will be able to test which items are checked. The class CMySuperGrid which is derived from CSuperGridCtrl shows you how to initalize the grid, insert root items, insert items, sort items, associate controltypes and how to implement 'print preview' selected or checked items depending on which extended style you have set, it also shows you have to search for items, select items, delete items and how to set the current listview icon and individual cell color. The source code shows you how to use the listview control in a CView derived class and in a CDialog derived class.

The listview control was built with Visual C++ 6.0 (sp10) level 8 on Windows 2000 beta 9, I don't remember the Netcard ID ;-).

In the SuperGridCtrl.h header file you will find further information/documentation on how to use this listview control. I have included a "history" section in the SuperGridCtrl.cpp file.

Drop me a line when you find that bug or if you have any comments / suggestions / improvement at all to this listview control.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalvery good Pin
bishanhu6-Jun-06 3:37
bishanhu6-Jun-06 3:37 
Generalwrong version in the download link Pin
banbanyy8-Feb-06 1:39
banbanyy8-Feb-06 1:39 
Questionany one immplemented LVS_EX_HEADERDRAGDROP to this?? Pin
kumar_anand8-Dec-05 23:19
kumar_anand8-Dec-05 23:19 
QuestionHow to use SetItemData? Pin
HarveyLiu14-Aug-05 17:49
HarveyLiu14-Aug-05 17:49 
AnswerRe: How to use SetItemData? Pin
Danila Korablin25-Jun-07 5:34
Danila Korablin25-Jun-07 5:34 
QuestionHow to change Parent Item Pin
Tu Tran15-Jul-05 13:52
Tu Tran15-Jul-05 13:52 
Generalset check box after icons Pin
k_samsamsam_k7-Jul-05 23:55
k_samsamsam_k7-Jul-05 23:55 
GeneralRe: set check box after icons Pin
k_samsamsam_k8-Jul-05 0:06
k_samsamsam_k8-Jul-05 0:06 
Generalvery good,Thakns Pin
hpxs21-Jun-05 17:08
hpxs21-Jun-05 17:08 
QuestionHow can I realize the directory tree like the listview? Pin
blestrabbit13-Apr-05 17:02
blestrabbit13-Apr-05 17:02 
QuestionHow to do sorting depending on column data type? Pin
NikoletinaBursac8-Mar-05 7:43
NikoletinaBursac8-Mar-05 7:43 
GeneralDifferent Item Height Pin
hypercor17-Feb-05 1:20
hypercor17-Feb-05 1:20 
GeneralRe: Different Item Height Pin
iliyang16-Jun-05 9:20
iliyang16-Jun-05 9:20 
Generalmoving rows Pin
meir_elkabetz@hotmail.com16-Feb-05 4:13
sussmeir_elkabetz@hotmail.com16-Feb-05 4:13 
Questionhow can set a col is readonly Pin
Anonymous3-Nov-04 18:41
Anonymous3-Nov-04 18:41 
GeneralA Definite Bug Pin
myself29-Sep-04 7:30
myself29-Sep-04 7:30 
QuestionCan I use this in .net visual c++ Pin
Member 122430522-Sep-04 21:22
Member 122430522-Sep-04 21:22 
GeneralSorting is kinda weak Pin
LakeFerrits10-Aug-04 11:15
LakeFerrits10-Aug-04 11:15 
GeneralVERY hard to use Pin
jtorjo19-Jul-04 22:05
jtorjo19-Jul-04 22:05 
GeneralRe: VERY hard to use Pin
@llan25-Feb-05 21:02
@llan25-Feb-05 21:02 
GeneralRe: VERY hard to use Pin
jtorjo26-Feb-05 8:58
jtorjo26-Feb-05 8:58 
GeneralThis is VERY difficult to customize Pin
brdavid19-Jun-04 8:25
brdavid19-Jun-04 8:25 
GeneralRe: This is VERY difficult to customize Pin
brdavid5-Mar-05 8:43
brdavid5-Mar-05 8:43 
GeneralRe: This is VERY difficult to customize Pin
icecube418-Feb-05 9:06
sussicecube418-Feb-05 9:06 
GeneralEasy way to place this in custom app Pin
Anonymous5-Jun-04 0:48
Anonymous5-Jun-04 0:48 

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

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