Click here to Skip to main content
15,886,724 members
Articles / Desktop Programming / MFC

Multicolumn Combobox with Additional Format Conditions

Rate me:
Please Sign up or sign in to vote.
4.33/5 (2 votes)
9 May 2007CPOL2 min read 78.8K   5.3K   39  
Multicolumn Combobox with additional format conditions depending on the displayed values
#pragma once

#include "MCCell.h"
#include "MCColumn.h"
#include "MCRow.h"
#include "FormatCondition.h"

// CMCComboBox

class CMCComboBox : public CComboBox
{
	DECLARE_DYNAMIC(CMCComboBox)

public:
	CMCComboBox();
	virtual ~CMCComboBox();

			//	sets the zero based display column index. It's value is shown in the edit control. If this function isn't called,
			//	the first added column will be the display column
			void				 Set_DisplayColumnIndex				( int nDisplayColumnIndex );
			//	adds a new column to the combobox.
			CMCColumn			*Add_Column							( CMCColumn::ColumnAlignment eColumnAlignment = CMCColumn::CA_AlignmentLeft );
			
			//	adds a new (allready created) row to the dropdown list
			bool				 Add_Row							( CMCRow *pRowData );
			//	creates a new row , adds it to the dropdown list and returns the pointer to the row object (NULL on failure)
			CMCRow				*Add_Row							( void );
			//	returns a pointer to the referenced row (index offset is 0). NULL if ItemID is out of range
			CMCRow				*Get_Row							( int nItemID );
			//	returns a pointer to the first matching format condition. If no format condition matches, the default format condition is returned
			//	if no default format condition is defined, NULL is returned
			CFormatCondition	*Get_FormatCondition				( CMCRow *pRow );
			//	creates a new format condition. The objects that are/might be referenced by the variables pValue1 and pValue2 are freed during 
			//	destruction of the format condition
			CFormatCondition	*Create_FormatCondition				( CString strFormatConditionName, int nColumnIndex, 
																	  CFormatCondition::eFormatConditionOperator eFormatConditionOperator,
																	  CMCCell *pValue1, CMCCell *pValue2 = NULL );

			//	calculates the needed width of the dropdown list and sets it to the control.
			//	this function should be called after alls rows have been added or if cell data has changed
			void				 CalcDropdownListWidth				( void );

			//	returns a boolean value, that defined whether a found format condition should also be used to display
			//	the edit control value or not
			bool				 Get_ShowFormatConditionInEditField	( void );
			//	true  -> the found format condition is also used for displaying the value in the edit control
			//	false -> The value in the edit control is displayed "normal"
			void				 Set_ShowFormatConditionInEditField	( bool bShowFormatConditionInEditField );

private:

	virtual	void				 DrawItem							( LPDRAWITEMSTRUCT lpDrawItemStruct );
	virtual	void				 MeasureItem						( LPMEASUREITEMSTRUCT lpMeasureItemStruct );

			// A flag used in MeasureItem, see comments there
			bool				 m_bItemHeightSet;

			//	multicolumn additions
			int					 m_nDisplayColumnIndex;			//	columnindex - defines the columns which owns the data, that is displayed in the edit field. 
			CObList				 m_olColumns;
			CObList				 m_olFormatConditions;
			CObList				 m_olRows;
			CMCRow				*m_pRowToBeAdded;			//	row is added, but the itemdata is not yet added to the new entry.
			bool				 m_bShowFormatConditionInEditField;

protected:

	DECLARE_MESSAGE_MAP()
public:
	virtual int CompareItem(LPCOMPAREITEMSTRUCT /*lpCompareItemStruct*/);
};


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
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions