Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / MFC

An MFC-CListCtrl derived class that allows other ‘controls’ to be inserted into a particular cell

Rate me:
Please Sign up or sign in to vote.
4.92/5 (54 votes)
5 Jan 2014CPOL12 min read 167.4K   13.9K   160  
A class derived from CListCtrl that allows edit controls, combo boxes, check boxes, date pickers, and color pickers to be inserted into or removed from particular cells extremely easily. The inserted 'controls' are not CWnd-derived.
#pragma once

#include "CellDropDown.h"

class CPopUpScrollList;

class CCellComboBox : public CCellDropDown  
{
	friend CPopUpScrollList;
public:
	CCellComboBox();
	virtual ~CCellComboBox();
	virtual void Initialize(HWND hParentWnd, BOOL *pParentEnabled, LPCTSTR strText);
	virtual void DrawCtrl(CDC *pDC, const LPRECT prcCell, UINT uiItemState = 0);
	virtual void DrawItem(CDC *pDC, const LPRECT prcItem, const CString &strLabel, BOOL bSelected = FALSE, BOOL bDisabled = FALSE);
	virtual int GetMinWidth();

	inline LONG GetDisplayedRows() const 
	{
		return m_lDisplayedRows;
	}
	inline void SetDisplayedRows(LONG lDisplayedRows)
	{
		m_lDisplayedRows = lDisplayedRows;
	}
	inline LONG GetSelectedItem() const
	{
		return m_lSelectedItem;
	}
	virtual BOOL OnMouseMove(UINT nFlags, CPoint point); 
	virtual void AddToCtrlTypeStyle(DWORD dwFlags);
	virtual void RemoveFromCtrlTypeStyle(DWORD dwFlags);
	virtual LONG GetStyle();
	BOOL InsertItem(int Idx, LPCTSTR strText);
	BOOL SetSelectedItem(LONG lSelectedItem);
	BOOL RemoveItem(int Idx);
protected:
	BOOL			m_bHighlighted;
	LONG			m_lDisplayedRows,
					m_lSelectedItem;
	CStringArray	m_astrItems;

	virtual void OnOpenDropDown();
	virtual void GetDropDownBoundingRect(RECT &rc, BOOL downwards /*= TRUE*/);
	virtual void OnSelCloseDropDown(LPARAM lParam);
private:
	static DWORD	m_dwComboStyle; 
};

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)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions