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

Report control - an Outlook 2000 style SuperGrid Report Control

By , 14 Jun 2001
 

Sample Image

Introduction

This ReportCtrl control is an Outlook 98/2000 style SuperGrid control. I've seen many implementations, most of them based on the standard CListCtrl. All implementations have their specific weaknesses. This implementation tries to overcome some of the weaknesses, although for some purposes it may introduce others.

The documentation is sparse, because I do not have much time to write documentation. However, the included demo is a great help in understanding how to use the features of the control and many features are demonstrated in a practical manner. The interfaces of the controls highly resemble the interfaces of similiar MFC controls, like the list control and header control. So, for the more experienced MFC coder, it should not be a big problem to understand how to use the control in their own projects...

Version History Excerpt (refer to source file for complete history)

This ReportCtrl control is an Outlook 98/2000 style SuperGrid control. I've seen many implementations, most of them based on the standard CListCtrl. All implementations have their specific weaknesses. This implementation tries to overcome some of the weaknesses, although for some purposes it may introduce others.

The documentation is sparse, because I do not have much time to write documentation. However, the included demo is a great help in understanding how to use the features of the control and many features are demonstrated in a practical manner. The interfaces of the controls highly resemble the interfaces of similiar MFC controls, like the list control and header control. So, for the more experienced MFC coder, it should not be a big problem to understand how to use the control in their own projects...

Version history excerpt (refer to source file for complete history):

2.0.1	- Fixed bug in DeleteItem for tree control mode.
	- Fixed item expansion for single subitem hierarchy items.
	- Added GetExpandedItemText to allow expanded items to show different
	  text from the subitem text.
	- Added support for radio button and disabled check marks and 
	  radio buttons.
	- Added RVP_ENABLEFLATCHECKMARK property, to control the visual style
	  of check marks or radio buttons.
	- Added support for check mark and radio button image list.
	- Changed CurrentFocus() to GetCurrentFocus().
	- Changed OnKillFocus to recognize all child windows.
	- Extended MeasureItem function.
	- Fixed GetNextItem() for RVTI_ROOT.
	- Added support for SetRedraw suggested by Phil J Pearson.
	- Optimized InsertItem performance by skipping GetRowFromItem
	  when the focus is not on an reorderable row, as suggested by
	  Phil J Pearson.
	- Added disabled background function to CReportSubItemListCtrl.
	- Added pre-create style passing to CReportView.
	- Adjusted edit box position.
	- Fixed a bug related to keydown messages in unfocused state.
	- Fixed tip redraw problem and tip background color mismatch.
	- Fixed kill tip on WM_KILLFOCUS, finally fixing click and double
	  click on expanded subitems.
	- Added GetSelectedItems method.
	- Fixed a selection bug in ClearSelection.
	- Made GetReportCtrlPtr virtual and changed CReportView to use
	  overriden function to get a pointer to the embedded CReportCtrl.
	  This allows control derived from CReportCtrl to be embedded in 
	  CReportView.
	- Added UpdateWindow to SetRedraw when re-enabling redrawing.
	- Removed legacy definitions from header file.
	- Added blended image support through state bits, focus and selection
	  through the RVP_ENABLEIMAGEBLENDING and RVP_BLENDCOLOR properties.
	- Added support for overlay images.
	- Added Win2K tip fading to CReportTipCtrl.
	- Fixed nFormat subitem member update in OnHdnItemChanged, as
	  suggested by Sven Ritter.
	- Added selective item cache flush to SetItemCount.
	- Added GetItemString() function to retrieve an item as a string.
	- Added clipboard Copy support and clipboard separator and indent
	  properties.
	- Fixed OnRvnEndItemEdit to not loose lParam, as suggested by
	  Paul Hurley.
	- Added GetSortSettings() to retrieve sorting settings.
	- Made SelectRows virtual to allow owner data multiple selection
	  management.
	- Fixed a bug in DeleteItem for trees.
	- Fixed various mouse button, keyboard selection/focus issues.
2.0.0	- Made scrolling with left or right cursor key dependent on
	  focus subitems style.
	- Fixed resource leak in empty list, as suggested by Florent
	  Odelain.
	- Fixed ResortItems and DeactivateSubItem bugs as suggested by
	  Rafael Lombardi Santos.
	- Fixed HitTest on reordered columns, reported by Trevor Ash.
	- Fixed item rect returned in hitinfo structure for scrolled
	  controls. This fixes incorrect positioning of tip windows.
	- Added CReportHeaderCtrl to access CFlatHeaderCtrl's protected
	  members.
	- Added first column indent functions, to support hierarchy
	  GUI elements.
	- Fixed HitTest to retrieve correct item data.
	- Added parameter to sort callback.
	- Removed SortAllSubItems, because implementation was not
	  maintained and buggy.
	- Fixed IsItemVisible and added GetTopIndex(), PageUp() and
	  PageDown() as suggested by Alina Kozlovsky.
	- Added tree control features, both in preparation of group
	  view mode as well as a standalone feature.
	- Fixed subitem text drawing following uninitialized subitems.
	- Changed CompareItems callback and functions to support
	  separate subitems to enable tree view and group view sorting.
	- Extended CompareItems to sort on checkboxes as suggested by
	  Peter Lagerhem.
	- Fixed offset of subitem tip for items with images or checks
	  and text and related hittesting issues.
	- Fixed NOHEADER style.
	- Changed selected items and tree boxes in tree view mode visuals
	  to match common control look and feel.
	- Fixed default height setting for font size updates with images.
	- Fixed cosmetic bug with RVS_SHOWHGRID style, as suggested by Matrix.
	- Fixed SelectAll() for empty control as suggested by Dmitry Sazonov.
	- Added GetStyle().
	- Added RVN_HEADERRCLICK to support popup menus on header.
	- Fixed tooltip double click and ALT key relay events by removing
	  mouse capture.

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

About the Author

Maarten Hoeben
Web Developer
Netherlands Netherlands
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   
QuestionScrollBar problem with resizing dialogs. [modified]memberdchris_med23 Apr '13 - 21:26 
I hosted this control inside a resizing dlg among other windows in a dlg based app..which had custom background painting.
 
I noticed that each time I re-sized the main dlg wnd..the scroll-bars got dirty until I passed the mouse over the scrollbar. This happens only on right-sizing, not down, and when the control's width becomes bigger than header's width. I traced the code to
 
CReportCtrl::ScrollWindow(INT iBar, INT iPos)
 
and since happened only on right ...I fount the difference in moving the header control.
 
I replaced
INT cx = iWidth<m_iVirtualWidth ? m_iVirtualWidth:iWidth;
 
with
 
INT cx = m_iVirtualWidth;//iWidth<m_iVirtualWidth ? m_iVirtualWidth:iWidth;


modified 24 Apr '13 - 10:45.

QuestionPer sub item colours [modified]memberdchris_med27 Mar '12 - 15:49 
Wink | ;)
 
BOOL CReportCtrl::SetItemTextColor(INT iItem, INT iSubItem, COLORREF crColor)
{
	BOOL bFound = 0;
	int i = 0;
	int iColors = m_arrayColors.GetSize();
	for (i=0;i<iColors;i++){
		if(m_arrayColors[i]==crColor){
			bFound=1;
			break;
		}
	}
 
	RVITEM rvi;	
	rvi.iItem = iItem;
	rvi.iSubItem = iSubItem;
	rvi.nMask = RVIM_TEXTCOLOR;
	if(bFound){
		rvi.iTextColor = i;
	}
	else{
		rvi.iTextColor =InsertColor(iColors, crColor);
	}
	return SetItem(&rvi);
}
 
BOOL CReportCtrl::SetLineTextColor(INT iItem, COLORREF crColor)
{
	int iCol = m_arrayColumns.GetSize(),i;
	for (i=0;i<iCol;i++){
		if(!SetItemTextColor(iItem, i, crColor))
			return FALSE;
	}
	return TRUE;
}
CGSoftLabs.


modified 27 Mar '12 - 22:10.

QuestionProblems with VS2010membericaro28 Jul '10 - 2:09 
After having fixed some errors due to changes to the compiler I compiled and run the demo, but it doesn't work as in VS2003: fields on the 2nd lines are left blank and resize of columns behaves strangely. I debugged a bit and it seems like WM_NOTIFY messages are not trapped. Has anyone a clue to fix this behavior?
 
thanks a lot.
AnswerRe: Problems with VS2010memberPhil J Pearson31 Jul '10 - 1:20 
I have noticed the same resizing problem and reached the same conclusion about notify messages but I haven't yet found a solution. Have you found anything?
Phil
 


The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

GeneralWorkaroundmembericaro3 Aug '10 - 6:04 
Don't think this is the most elegant solution but it worked for me.
For some (obscure) reasons the message pump for ON_NOTIFY in not working anymore. I removed all the ON_NOTIFY from the Message Map and added this:
 
BOOL CReportCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
   switch (((LPNMHDR)lParam)->code)
    {
    case RVN_ENDITEMEDIT:
		OnRvnEndItemEdit((NMHDR *)lParam, pResult);
		return *pResult;
    case HDN_ITEMCHANGED:
		OnHdnItemChanged((NMHDR *)lParam, pResult);
		return *pResult;
	case HDN_ITEMCLICK:
		OnHdnItemClick((NMHDR *)lParam, pResult);
		return *pResult;
	case HDN_BEGINDRAG:
		OnHdnBeginDrag((NMHDR *)lParam, pResult);
		return *pResult;
	case HDN_ENDDRAG:
		OnHdnEndDrag((NMHDR *)lParam, pResult);
		return *pResult;
	case HDN_DIVIDERDBLCLICK:
		OnHdnDividerDblClick((NMHDR *)lParam, pResult);
		return *pResult;
	default:
		;
	}
 
	return CWnd::OnNotify(wParam, lParam, pResult);
}
 
everything seems to work as before.
GeneralRe: WorkaroundmemberPhil J Pearson4 Aug '10 - 23:07 
Thanks.
I actually started to do something like that but then I decided to ditch all the code in favour of a simpler report control that just met all my needs. I'll remember your solution in case I ever need the more complete report control again.
Phil
 


The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

GeneralRe: WorkaroundmemberMember 17562327 Oct '10 - 8:51 
I fixed the NOTIFY problem by replacing in reportdemoview.cpp the ON_NOTIFY definitions with ON_NOTIFY_REFLECT, for example replace:
 
ON_NOTIFY(RVN_ITEMDRAWPREVIEW, 0, OnRvnItemDrawPreview)
 
with
 
ON_NOTIFY_REFLECT(RVN_ITEMDRAWPREVIEW, OnRvnItemDrawPreview)
AnswerRe: Problems with VS2010memberSteveKing5 Dec '12 - 0:10 
How to fix this problem:
 
in ReportCtrl.h, replace
#define ID_HEADERCTRL   0
with e.g.
#define ID_HEADERCTRL   1243
 
in ReportCtrl.cpp, replace:
    ON_NOTIFY(HDN_ITEMCHANGED, 0, OnHdnItemChanged)
    ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemClick)
    ON_NOTIFY(HDN_BEGINDRAG, 0, OnHdnBeginDrag)
    ON_NOTIFY(HDN_ENDDRAG, 0, OnHdnEndDrag)
    ON_NOTIFY(HDN_DIVIDERDBLCLICK, 0, OnHdnDividerDblClick)
    ON_NOTIFY(RVN_ENDITEMEDIT, 0, OnRvnEndItemEdit)
with
    ON_NOTIFY(HDN_ITEMCHANGED, ID_HEADERCTRL, OnHdnItemChanged)
    ON_NOTIFY(HDN_ITEMCLICK, ID_HEADERCTRL, OnHdnItemClick)
    ON_NOTIFY(HDN_BEGINDRAG, ID_HEADERCTRL, OnHdnBeginDrag)
    ON_NOTIFY(HDN_ENDDRAG, ID_HEADERCTRL, OnHdnEndDrag)
    ON_NOTIFY(HDN_DIVIDERDBLCLICK, ID_HEADERCTRL, OnHdnDividerDblClick)
    ON_NOTIFY(RVN_ENDITEMEDIT, ID_HEADERCTRL, OnRvnEndItemEdit)

Generalsmall bugfixmemberdiamond28 May '09 - 7:09 
I've found that when the grid has focus, but all items are disabled (not sure what else is required to reproduce), you will get an index out of bounds exception if you press SPACE. To fix this, modify CReportCtrl::OnKeyDown like this (new row is bold):
...
if(!Notify(&nmrv))
{
switch (nChar)
{
case VK_SPACE:
if(m_iFocusRow != RVI_INVALID)
SelectRows(m_iFocusRow, m_iFocusRow, TRUE, TRUE, IsCtrlDown() ? TRUE:FALSE);
return;
...
QuestionTree Sub ItemsmemberC_BRUMLEY5 Nov '08 - 7:01 
Hello, thanks for this control.
 
I've been playing with the demo and have a question. How can I create a subitem that is a tree? All of the examples I've seen of this control create the tree in the first column, but I'd like to have a tree start in the 2nd column.
 
Is that possible?
 
I've tried the following in the tree view example in dialogs.cpp
m_rcTest.InsertItem("Test Root",-1,-1,-1,RVTI_ROOT,((HTREEITEM)(ULONG_PTR)-65534),1);
 
which should create Test Root in the subitem, as long as there's data in the first column, but this doesn't appear to work. It appears that InsertItem eventually assumes a subitem of 0.
 
Any ideas on how to implement this?

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 15 Jun 2001
Article Copyright 2000 by Maarten Hoeben
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid