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

SuperGrid - Yet Another listview control

By , 8 Dec 1999
 

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)

About the Author

Allan Nielsen
Switzerland Switzerland
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralIt looks so good.memberN1i2c3k8 Jun '07 - 19:31 
It looks so good.Smile | :)
QuestionI need some help about delete itemsmemberStarsrain4 Apr '07 - 15:37 
my data is dynamic load from database,and i have carried it out only in the this
 
control.
my problem is i used the tree to control the data display in the list
tree control.On this way,i selchanged on the my tree control need display the data
 
in the list tree.at first,In my tree control selchange function i used the
 
deleteAll() function to delete the list tree all items and display the new
 
data.when i use the deleteall function the program will be intermitted. when i
 
used the DeleteAllItems() function to delete the list tree data,itself delete the
 
child node and display the child node function will be error.it display the data
 
not right.
like this:
+Root1
+Root2
+Root3
expend the Root1 then Root2 node will be delete and collapsed the Root1 it can't
 
delete itself children.
 
someone can help me or give me some suggestion,thanks
QuestionDo you have a VB OO compatible version or OCX ?memberMCMikey6921 Mar '07 - 7:40 
Hi,
 
This is fantastic and just what I need. However, I'm using VB6 to write my app (loads of very good reasons for that which I won't go into). Do you have the control compiled as an OCX?
 
Cheers,
Mike May
Big Grin | :-D
GeneralBug in check boxesmember_faraz12 Mar '07 - 0:48 
Settting the check in a root level item does not work. For example the following code addition to the demo (InitializeGrid method) fails to set the check:
 

CItemInfo* lp = new CItemInfo();
lp->SetCheck(1);
lp->SetImage(4);

//add item text
lp->SetItemText(_T("Hello World"));
//add subitem text
lp->AddSubItemText(_T("Happy"));
....
 

I'm hunting this bug down now...
 
faraz
GeneralRe: Bug in check boxesmember_faraz12 Mar '07 - 1:33 
To fix:
 
In CSuperGridCtrl::InsertRootItem(CItemInfo * lpInfo)
 
starting line 1488:
 
     CItemInfo* lp = GetData(pRoot);
     LV_ITEM lvItem;         
     lvItem.mask = LVIF_TEXT | LVIF_INDENT | LVIF_PARAM;
     CString strItem = lp->GetItemText();
     lvItem.pszText = strItem.GetBuffer(1);
     lvItem.iItem = GetItemCount();
     lvItem.lParam = (LPARAM)pRoot;
     lvItem.iIndent = 1;
     lvItem.iSubItem = 0;
     CListCtrl::InsertItem(&lvItem);
//Add this line in to let CListCtrl know about the check
     SetCheck(lvItem.iItem, lpInfo->GetCheck());
 
** Sometimes you know yourself something is a bad idea; follow your instinct Smile | :) **
 
                    //yes I know..have to maintain to sets of checkstates here...
                    //one for listview statemask and one for CTreeItem..but its located here so no harm done
                    SetCheck(ht.iItem,!GetCheck(ht.iItem));
                    CItemInfo *pInfo = GetData(pItem);
                    pInfo->SetCheck(!pInfo->GetCheck());
Questionhow do you implement it ?membershuaicarr25 Jan '07 - 18:24 
First,i should say thanks to your effort.i take advantage of your control in my own project. but i think the interface is too large to manipulate.
 
would you give me a description on how do you combine "LIST" with "TREE" ?
the tree like thing is in the first column .when a tree subitem collapses ,the relevent items in list acts accordingly . how does it work ?
QuestionNested List-Control with Column-Headers ?memberwebspektive7 Dec '06 - 4:34 
Do you have any plans to implement nested List-Controls or Supergrids instead of 'normal' rows (like FlyGrid.Net or Sandgrid) ?
GeneralReally useful but is it possible? [modified]membercrazydave2223 Oct '06 - 4:27 
Really useful but is it possible to add checkboxes to the SuperGrid in the dialog?
 
Do the controls work also in the dialog view?
Can't get them to work.
 
I would really appreciate anyones help?Sigh | :sigh:
 
I'm not daft, just stupid really!!!
 

-- modified at 8:12 Tuesday 24th October, 2006
Question1. Does anybody know how to implement Multiselection ( Rows ) into this fine piece of code?memberhawonjeon10 Oct '06 - 20:26 
1. Does anybody know how to implement Multiselection ( Rows ) into this fine piece of code?
 
^^dssfasdfadsafasdfasdfasdfasdf

AnswerRe: 1. Does anybody know how to implement Multiselection ( Rows ) into this fine piece of code?membertangshengye29 Oct '08 - 2:24 
I am waiting for this as well. Laugh | :laugh:

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 9 Dec 1999
Article Copyright 1999 by Allan Nielsen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid