Click here to Skip to main content
14,217,336 members
Click here to Skip to main content

Stats

2.2M views
59.1K downloads
447 bookmarked

CGridListCtrlEx - Grid Control Based on CListCtrl

,
Rate this:
4.90 (130 votes)
Please Sign up or sign in to vote.
4.90 (130 votes)
16 Mar 2015     CPOL    
A custom draw CListCtrl with subitem editing and formatting
CGridListCtrlEx
DemoApplication
res
CGridListCtrlEx.ico
FLGDEN.ICO
FLGFRAN.ICO
FLGGERM.ICO
FLGGREEC.ico
FLGSPAIN.ICO
FLGSWED.ICO
Documentation
CGridListCtrlEx
screenshot.png
vs2003
CGridListCtrlEx.vcproj
vs2005
CGridListCtrlEx.vcproj
vs2008
CGridListCtrlEx.vcproj
vs6
CGridListCtrlEx.dsp
CGridListCtrlEx.dsw
Release
CGridListCtrlEx.exe
msvcp120.dll
msvcr120.dll
CGridListCtrlEx.ico
FLGDEN.ICO
FLGFRAN.ICO
FLGGERM.ICO
FLGGREEC.ico
FLGSPAIN.ICO
FLGSWED.ICO
screenshot.png
Doxygen
Doxyfile
html
arrowdown.png
arrowright.png
bc_s.png
bdwn.png
class_c_grid_column_trait.png
class_c_grid_column_trait_combo.png
class_c_grid_column_trait_date_time.png
class_c_grid_column_trait_edit.png
class_c_grid_column_trait_hyper_link.png
class_c_grid_column_trait_image.png
class_c_grid_column_trait_multiline_edit.png
class_c_grid_column_trait_text.png
class_c_grid_editor_combo_box.png
class_c_grid_editor_combo_box_edit.png
class_c_grid_editor_date_time_ctrl.png
class_c_grid_editor_text.png
class_c_grid_list_ctrl_ex.png
class_c_grid_list_ctrl_groups.png
class_c_grid_multiline_editor_text.png
class_c_grid_row_trait.png
class_c_grid_row_trait_text.png
class_c_grid_row_trait_x_p.png
class_c_view_config_section.png
class_c_view_config_section_default.png
class_c_view_config_section_default_1_1_c_view_config_section_local.png
class_c_view_config_section_profiles.png
class_c_view_config_section_win_app.png
closed.png
doc.png
doxygen.png
folderclosed.png
folderopen.png
ftv2blank.png
ftv2cl.png
ftv2doc.png
ftv2folderclosed.png
ftv2folderopen.png
ftv2lastnode.png
ftv2link.png
ftv2mlastnode.png
ftv2mnode.png
ftv2mo.png
ftv2node.png
ftv2ns.png
ftv2plastnode.png
ftv2pnode.png
ftv2splitbar.png
ftv2vertline.png
nav_f.png
nav_g.png
nav_h.png
open.png
search
close.png
mag_sel.png
search_l.png
search_m.png
search_r.png
splitbar.png
sync_off.png
sync_on.png
tab_a.png
tab_b.png
tab_h.png
tab_s.png
CGridListCtrlEx.vcproj
CGridListCtrlEx.vcproj
CGridListCtrlEx.vcproj
CGridListCtrlEx.dsp
CGridListCtrlEx.dsw
#pragma once

//------------------------------------------------------------------------
// Author:  Rolf Kristensen	
// Source:  http://www.codeproject.com/KB/list/CGridListCtrlEx.aspx
// License: Free to use for all (New BSD License)
//------------------------------------------------------------------------

#include "CGridColumnTraitText.h"

//------------------------------------------------------------------------
//! CGridColumnTraitImage implements an image switcher (can mimic a checkbox)
//!
//! By adding checkbox state-images to the official imagelist using
//! AppendStateImages(), then one can use this column trait as checkbox
//! editor. To get/set the checkbox value of a cell use the methods
//! GetCellImage()/SetCellImage() on CGridListCtrlEx
//------------------------------------------------------------------------
class CGridColumnTraitImage : public CGridColumnTraitText
{
public:
	CGridColumnTraitImage();
	CGridColumnTraitImage(int nImageIndex, int nImageCount);

	void AddImageIndex(int nImageIdx);
	void AddImageIndex(int nImageIdx, const CString& strImageText, bool bEditable = true);

	void SetImageText(int nImageIdx, const CString& strImageText, bool bEditable = true);

	void SetSortImageIndex(bool bValue);
	bool GetSortImageIndex() const;

	void SetToggleSelection(bool bValue);
	bool GetToggleSelection() const;

	void SetSingleClickEdit(bool bValue);
	bool GetSingleClickEdit() const;

	void SetIconClickBeginEdit(bool bValue);
	bool GetIconClickBeginEdit() const;

	static int AppendStateImages(CGridListCtrlEx& owner, CImageList& imagelist);
	static LRESULT SendEndLabelEdit(CWnd& wndListCtrl, int nRow, int nCol, LV_DISPINFO& dispInfo);

protected:
	virtual int OnSortRows(LPCTSTR pszLeftValue, LPCTSTR pszRightValue, bool bAscending) { return CGridColumnTraitText::OnSortRows(pszLeftValue, pszRightValue, bAscending); }
	virtual int OnSortRows(const LVITEM& leftItem, const LVITEM& rightItem, bool bAscending);
	virtual bool IsCellReadOnly(CGridListCtrlEx& owner, int nRow, int nCol, CPoint pt) const;
	virtual int OnClickEditStart(CGridListCtrlEx& owner, int nRow, int nCol, CPoint pt, bool bDblClick);
	virtual CWnd* OnEditBegin(CGridListCtrlEx& owner, int nRow, int nCol) { return CGridColumnTraitText::OnEditBegin(owner, nRow, nCol); }
	virtual CWnd* OnEditBegin(CGridListCtrlEx& owner, int nRow, int nCol, CPoint pt);
	virtual void Accept(CGridColumnTraitVisitor& visitor);
	virtual int FlipImageIndex(CGridListCtrlEx& owner, int nRow, int nCol);
	virtual CWnd* OnEditBeginImage(CGridListCtrlEx& owner, int nRow, int nCol);
	virtual CWnd* OnEditBeginCheckbox(CGridListCtrlEx& owner, int nRow, int nCol);

	//! @cond INTERNAL
	struct ImageCell
	{
		CString m_CellText;
		bool m_Editable;

		ImageCell()
			: m_Editable(true) {}
		ImageCell(const CString& cellText, bool editable)
			: m_CellText(cellText), m_Editable(editable) {}
	};
	//! @endcond INTERNAL

	CSimpleMap<int,ImageCell> m_ImageIndexes;	//!< Fixed list of image items to switch between

	bool m_SortImageIndex;	//!< Should image be used as primary sort index ?
	bool m_ToggleSelection;	//!< Should the image of all selected rows be flipped, when clicked ?
	bool m_SingleClickEdit;	//!< Should it start editor on first click, instead of first waiting for cell to have focus first
	bool m_IconClickBeginEdit; //!< Should it start editor when clicking the icon area ?
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Rolf Kristensen
Software Developer
Denmark Denmark
No Biography provided