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   
Questionocx file for use in VB6memberL B Choudhury28 Jan '13 - 19:06 
Can some one help me with an ocx file of this cute code so that the same can be used in VB6 for saving and retrieving data from .mdb file.
QuestionHow to real delete all, include column header? [modified]memberJason Tian19 Nov '11 - 19:55 
First, I want to say, this code is really really excellent.
 
I try to update the supergrid in run-time, such as, add or delete some columns, so first i call the function of SuperGrid "DeleteAll" but it just deletes items of list, not include columns. And then i modified the code in "CMySuperGrid" function "_DeleteAll"by the codes below:
 
void CMySuperGrid::_DeleteAll()
{
	DeleteAll();//call CSuperGridCtrl::DeleteAll();
        // here i add header deleting==============BEGIN
	CHeaderCtrl* pHeader=this->GetHeaderCtrl();
	int i, nCount=pHeader->GetItemCount();
	for(i=nCount-1; i>=0; i--)
		pHeader->DeleteItem(i);
 
	LPTSTR lpszCols[] = {_T("Tree thing"),_T("Column #1"),_T("Column #2"),_T("Column #3"),_T("Column #4"),_T("Column #5"),0};
	LV_COLUMN   lvColumn;
	//initialize the columns
	lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvColumn.fmt = LVCFMT_LEFT;
	lvColumn.cx = 200;
	for(int x = 0; lpszCols[x]!=NULL; x++)
    {
		//make the secondary columns smaller
		if(x)
		  lvColumn.cx = 150;
 
		lvColumn.pszText = lpszCols[x];
		InsertColumn(x,&lvColumn);
    }
        // here i add header deleting, and recreate columns==============END

	//add some new data
	CItemInfo* lp = new CItemInfo();
	lp->SetImage(4);
	//add item text
	lp->SetItemText(_T("New data"));
	//Create root item
	CTreeItem * pRoot = InsertRootItem(lp);//previous we call CreateTreeCtrl(lp)
	if( pRoot == NULL )
		return;
	//insert items	
	int nCol = GetNumCol();
	for(i=0; i < nCol; i++)
	{
		CItemInfo* lpItemInfo = new CItemInfo();
		CString strItem;
		strItem.Format(_T("Item %d"),i);
		//add items text
		lpItemInfo->SetItemText(strItem);
		//add subitem text
		for(int y=0;y < nCol-1; y++) 
		{
			CString str;
			str.Format(_T("subItem %d of %s"),y,lpItemInfo->GetItemText());
			lpItemInfo->AddSubItemText(str);
			lpItemInfo->AddSubItemText(str);
		}
		//insert the iteminfo with ParentPtr
		CTreeItem* pParent = InsertItem(pRoot, lpItemInfo);
		//other nodes
		if(i%nCol)
		{
			CTreeItem* pParent1=NULL;
			CTreeItem* pParent2=NULL;
			for(int x=0; x < nCol; x++)
			{
				CItemInfo* lpItemInfo = new CItemInfo();
				CString strItem;
				strItem.Format(_T("Item %d"),x);
				lpItemInfo->SetItemText(strItem);
				for(int z=0; z < nCol-1; z++) 
				{
					CString str;
					str.Format(_T("subItem %d of %s"),z, lpItemInfo->GetItemText());
					lpItemInfo->AddSubItemText(str);
				}
				pParent1 = InsertItem(pParent, lpItemInfo);
				
			}
		}
	}
	//expand one level
	Expand(pRoot, 0 /*listview index 0*/); 
	UINT uflag = LVIS_SELECTED | LVIS_FOCUSED;
	SetItemState(0, uflag, uflag);
}
but after this, readd columns and items, it shows some different, after drawing, there are columns at the end of the this new columns i created. how could i recreate the columns and items.

modified 20 Nov '11 - 13:34.

GeneralRe: How to real delete all, include column header?member@llan9 Dec '11 - 5:26 
cool, nice work.
cheers Allan Big Grin | :-D
Questionhow to add Icon To this SuperListmemberthanhl0v37 Mar '11 - 16:54 
i Get Icon of a process and i don't know to add it to SuperList
 

// on OninitDlg
m_List.SetImageList (CImageList::FromHandle (GetSystemImageList (FALSE)), LVSIL_NORMAL);
//a function
HIMAGELIST CTreeListDlg::GetSystemImageList(BOOL bLarge)
{
	SHFILEINFO sfi;
	UINT uFlag = bLarge ? SHGFI_LARGEICON : SHGFI_SMALLICON;
	return (HIMAGELIST) SHGetFileInfo (TEXT (""), NULL, &sfi, sizeof (sfi), SHGFI_SYSICONINDEX | uFlag);
}
//and i get Icon of process
int CShowProcessTree::GetIcon(LPTSTR szPath, UINT uFlags)
{
	SHFILEINFO sfi;
	//MessageBox(szPath);
	SHGetFileInfo (szPath, NULL, &sfi, sizeof (sfi), SHGFI_SYSICONINDEX | uFlags);
	return sfi.iIcon;
}
 
i saw your function SetImage(index) to get index Image from BitMap
 
but how to add Icon Process to...when i got icon of it?
 
i added successful in Tree..but when i use your control...i don't know how
can you give me a funtion to add Icon (i got from SystemIcon of that Process)
thanks so much
sorry if my english is not good
QuestionIs there a way to edit the fields?membermatt200023 Jan '09 - 9:03 
I'm looking for a way to group edit boxes with labels. I want to keep it simple. I could use a grid if I needed to, but this looks a lot cleaner.
 
Thanks!
QuestionDialog based application [modified]memberkrishnanand2 Jul '08 - 3:16 
can u please explain me how to do the same in dialog based application?I have seen how to use the SuperGrid in dialog based application.But there is no check boxes available for items in dialog .Also I don't want the image icons.Can u please guide me how to achieve these things?
 
modified on Thursday, July 3, 2008 12:50 AM

QuestionColumn problem when dynamic settingmemberEva ranee17 Sep '07 - 23:50 
before go into DrawItem(), I set the column with the item's length in LVN_GETDISPINFO process function OnGetDispInfo().
But there are some problem in DrawItem() that i can't find the reason.
[problem]
suppose i have follow data:
[+]ICON aaa
[+]ICON aaaa
[+]ICON aaaaa
 
DrawItem() first:
[+]ICON aaa
 
DrawItem() second:
[+]ICON aaa
___________a // before 'a', nothing
 
DrawItem() third:
[+]ICON aaa
___________a // before 'a', nothing
____________a // before 'a', nothing
 
have some idea? Thank you very much!
 

 
Follow the C++ technical

QuestionMultiple column sortinmembersharathgowda10 Jul '07 - 2:35 
Hi
 
this is really fantastic control. I really like this.
 
Does this support multiple column sorting....
 
sharath b
 
"The world's biggest power is the youth and beauty of a woman."

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

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

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