Click here to Skip to main content
14,215,806 members
Click here to Skip to main content

Stats

2.2M views
59K 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 "CGridColumnTraitImage.h"

//------------------------------------------------------------------------
//! CGridColumnTraitCombo implements a CComboBox as cell-editor
//------------------------------------------------------------------------
class CGridColumnTraitCombo : public CGridColumnTraitImage
{
public:
	CGridColumnTraitCombo();

	void SetMaxItems(UINT nMaxItems);
	UINT  GetMaxItems() const;

	void SetStyle(DWORD dwStyle);
	DWORD GetStyle() const;

	void SetMaxWidth(UINT nMaxWidth);
	UINT  GetMaxWidth() const;

	void SetShowDropDown(BOOL bShowIt);
	BOOL GetShowDropDown() const;

	void LoadList(const CSimpleMap<DWORD_PTR,CString>& comboList, int nCurSel);
	void AddItem(DWORD_PTR nItemData, const CString& strItemText);
	void ClearFixedItems();

	virtual CWnd* OnEditBegin(CGridListCtrlEx& owner, int nRow, int nCol);
	virtual CWnd* OnEditBegin(CGridListCtrlEx& owner, int nRow, int nCol, CPoint pt) { return CGridColumnTraitImage::OnEditBegin(owner, nRow, nCol, pt); }
	virtual void  OnEditEnd();

protected:
	virtual void Accept(CGridColumnTraitVisitor& visitor);
	virtual CComboBox* CreateComboBox(CGridListCtrlEx& owner, int nRow, int nCol, DWORD dwStyle, const CRect& rect);

	CSimpleMap<DWORD_PTR,CString> m_ComboList;	//!< Fixed list of items in the combo-box
	CComboBox* m_pComboBox;					//!< CComboBox currently open
	DWORD m_ComboBoxStyle;					//!< Style to use when creating CComboBox
	UINT m_MaxItems;						//!< Max height (in items) of the CComboBox when doing dropdown
	UINT m_MaxWidth;						//!< Max width (in pixels) of the CComboBox when doing dropdown
	BOOL m_ShowDropDown;					//!< Show drop down of the CComboBox at edit begin

private:
	// Private because they doesn't handle CSimpleMap
	CGridColumnTraitCombo(const CGridColumnTraitCombo&);
	CGridColumnTraitCombo& operator=(const CGridColumnTraitCombo& other);
};

//------------------------------------------------------------------------
//! CEdit inside CComboBox for inplace edit. For internal use by CGridColumnTraitCombo
//
// Taken from "MFC Grid control" credits Chris Maunder
// http://www.codeproject.com/KB/miscctrl/gridctrl.aspx
//------------------------------------------------------------------------
class CGridEditorComboBoxEdit : public CEdit
{
public:
	CGridEditorComboBoxEdit();

protected:
	afx_msg void OnKillFocus(CWnd* pNewWnd);

	DECLARE_MESSAGE_MAP();

private:
	CGridEditorComboBoxEdit(const CGridEditorComboBoxEdit&);
	CGridEditorComboBoxEdit& operator=(const CGridEditorComboBoxEdit&);
};

//------------------------------------------------------------------------
//! CComboBox for inplace edit. For internal use by CGridColumnTraitCombo
//
// Taken from "MFC Grid control" credits Chris Maunder
// http://www.codeproject.com/KB/miscctrl/gridctrl.aspx
//------------------------------------------------------------------------
class CGridEditorComboBox : public CComboBox
{
public:
	CGridEditorComboBox(int nRow, int nCol, UINT nMaxWidthPixels, UINT nMaxHeightItems, BOOL bShowDropDown);

	virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
	virtual void EndEdit(bool bSuccess);

protected:
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnDestroy();
	afx_msg void OnDropDown();
	afx_msg void OnCloseUp();
	afx_msg void OnChangeSelection();
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);

	virtual void PostNcDestroy();
	virtual BOOL PreTranslateMessage(MSG* pMsg);

	DECLARE_MESSAGE_MAP();

	CGridEditorComboBoxEdit m_Edit;	//!< Subclassed edit control inside the CComboBox
	bool	m_Completed;			//!< Ensure the editor only reacts to a single close event
	bool	m_Modified;				//!< Register if selection was modified while the editor was open
	int		m_Row;					//!< The index of the row being edited
	int		m_Col;					//!< The index of the column being edited
	UINT	m_MaxWidthPixels;		//!< Max width (in pixels) of the CComboBox when doing dropdown
	UINT	m_MaxHeightItems;		//!< Max height (in items) of the CComboBox when doing dropdown
	BOOL	m_ShowDropDown;			//!< Show drop down of the CComboBox at edit begin

private:
	CGridEditorComboBox();
	CGridEditorComboBox(const CGridEditorComboBox&);
	CGridEditorComboBox& operator=(const CGridEditorComboBox&);
};

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

Layout: fixed | fluid

Article Copyright 2008 by Rolf Kristensen
Everything else Copyright © CodeProject, 1999-2019

Server Web01
Version 2.8.190619.2