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

Super Combo Box - combo-box with columns, colors and more

, 12 Apr 2004
Rate this:
Please Sign up or sign in to vote.
A CComboBox derived class that contains colors, columns, bold fonts, and images.

Sample Image - SuperComboBox.jpg

Motivation

I was looking around for a CComboBox derived class that would combine some features I needed - multiple columns, colors, icons and more.

Some of these features are found in other controls, but not under one roof, so I've decided to put them all together, in a simple way that will also have room for future growth.

Introduction

This class is a CComboBox derived class that enhances its functionalities:

  1. Multi-columns, when each column's width is controllable.
  2. An optional image-list can be supplied and an image can be set to the left of each row.
  3. Color of each row can be set.
  4. Each row can be bolded.

The code is based on Alex Hazanov's ComboBox Bold, just took it a bit further... thanks Alex.

Implementation

The WIN32/MFC implementation of a CComboBox provides DWORD element - Item Data, accessed via the SetItemData() and GetItemData() for storing extra information for each item of the combo-box. I used this member to store all the extra data I need to know of each row. This data is stored in the nested ItemData structure which is constructed for each element in the combo-box:

struct ItemData
{
    ItemData() : crTextColor(RGB(0,0,0)),nImageIndex(-1),bBold(FALSE),dwItemData(0){}
    COLORREF crTextColor;                // Row's color.
    int nImageIndex;                     // Index of the image in the image-list.
    std::map<int,CString> mapStrings;    // Map of string of all columns.
    BOOL bBold;                          // TRUE if the row is bolded.
    DWORD dwItemData;                    // Giving back the Item Data to the user...
};

All the new interface functions are added for setting the extra attributes of the combo-box by modifying the ItemData structure, and invalidating the combo-box.

For not loosing the original functionality of the CComboBox's SetItemData() and GetItemData(), the ItemData contains a DWORD member as well, that is accessed via the CComboBoxSuper.

A vector of all columns' width stores the width of all columns, and the size of this vector is also the number of columns in the combo-box.

Most of the job is done in the DrawItem function. This function is called for each item's drawing, and reads its item data, and draw the item accordingly.

Another function implemented is the virtual OnDeleteItem, which is called each time an element is removed from the combo-box, and deletes the ItemData of the element deleted from the combo-box, including ResetContent().

Usage

To use in a dialog - add a normal combo to the dialog, and replace the class from CComboBox to CComboBoxSuper.

Make sure to change the combo style to Owner Drawn Fixed and Has String in the resource editor, or by code.

To create on the fly - call create of the CComboBoxSuper object, and don't forget the styles.

Note: I always used the combo as a drop-list, in dropdown you get the first column's text only for editing.

During init function or all around the code, the following functions can be called:

  1. Setting to column number, and column width:

    void SetColumnCount(int nColumnCount); 
    /** Sets the number of columns to use - 
    new columns are inserted at default width. */
    
    void SetColumnWidth(int nColumnIndex, int nWidth); 
    /** Sets the width of a specific column. */
    m_ctrlSuperCombo.SetColumnCount(5);
    
    m_ctrlSuperCombo.SetColumnWidth(0, 100);
  2. Adding rows the combo (normal CComboBox function):

    m_ctrlSuperCombo.AddString("Row 1");
    m_ctrlSuperCombo.AddString("Row 2");
  3. Adding sub-item strings:

    void SetItemText(int nItemIndex, int nColumn, CString str); 
    /** Sets an item or sub-item text. */
    m_ctrlSuperCombo.SetItemText(1,1,"Yes");
    
    m_ctrlSuperCombo.SetItemText(2,1,"No");
  4. Setting a row color:

    void SetItemColor(int nItemIndex, COLORREF rcTextColor); 
    /** Sets a row's color. */
    m_ctrlSuperCombo.SetItemColor(1, RGB(255,0,0));
    
    m_ctrlSuperCombo.SetItemColor(2, RGB(0,128,0));
  5. Setting a row to bold (default is not bolded for all added rows):

    void SetItemBold(int nItemIndex, BOOL bBold = TRUE); 
    /** Set a specific row to bold. */
    m_ctrlSuperCombo.SetItemBold(2);
    
    m_ctrlSuperCombo.SetItemBold(1, FALSE);
  6. Setting images:

    void SetImageList(CImageList* pImageList); 
    /** Sets the image list to use - will be show 
    only if SetUseImage is called. */
    
    void SetItemImage(int nItemIndex, int nImageIndex); 
    /** Sets a row's image index. */
    
    void SetUseImage(BOOL bUseImage=TRUE) 
    /** Sets to TRUE for using the image list, 
    of FALSE to disable the use of the image-list. */
    m_ctrlSuperCombo.SetImageList(&m_ImageList);
    
    m_ctrlSuperCombo.SetUseImage();
    
    m_ctrlSuperCombo.SetItemImage(1, 1);

History

  • 20-03-2004 : Version 1.0 - First release.
  • 03-04-2004 : Change in documentations according to readers' requests.

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

Share

About the Author

ronhash
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
QuestionGood, It is my favorite Pinmembermaplewang2-Aug-12 0:23 
SuggestionCode : Auto Size Implementation PinmemberRAJKUMARV23-Mar-12 3:13 
Auto Size Implementation
 
MaskedComboBox.cpp
// MaskedComboBox.cpp : implementation file
//

#include "stdafx.h"
#include "MaskedComboBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CMaskedComboBox

CMaskedComboBox::CMaskedComboBox()
{
	//m_MaskChar.Format(" %c ",'-');
	//m_MaskChar = "";
	m_bAutoAlign = true;
	m_rgbBorderColor = RGB(192,192,192);
	m_rgbMaskColor = RGB(192,192,192);
	m_rgbIDColor = RGB(0,0,0);
	m_rgbDescColor = RGB(0,0,0);
}
CMaskedComboBox::CMaskedComboBox(char MaskChar)
{
	m_MaskChar.Format(" %c ",MaskChar);
}
CMaskedComboBox::CMaskedComboBox(CString csMaskChar)
{
	m_MaskChar= csMaskChar;
}
 
CMaskedComboBox::~CMaskedComboBox()
{
	_DumpMemory();
	m_MaskChar.ReleaseBuffer();
}
 
BEGIN_MESSAGE_MAP(CMaskedComboBox, CComboBox)
	//{{AFX_MSG_MAP(CMaskedComboBox)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CMaskedComboBox message handlers
void CMaskedComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	
	try
	{
		//CString cs;cs.Format("\n%d",lpDrawItemStruct->itemID);
		//OutputDebugString(cs);
		//Focus Highlight Implementation
		if((lpDrawItemStruct->itemState & ODS_SELECTED)) //GetFocus()->m_hWnd == m_hWnd &&
		{
			CDC dc;
			if(dc.Attach(lpDrawItemStruct->hDC) )
			{
				// Bakckup old settings
				COLORREF crOldTextColor = dc.GetTextColor();
				COLORREF crOldBkColor = dc.GetBkColor();
 
				if ((lpDrawItemStruct->itemAction | ODA_SELECT) || (lpDrawItemStruct->itemAction | ODA_FOCUS) &&
					(lpDrawItemStruct->itemState & ODS_SELECTED))
				{
					dc.SetBkMode(OPAQUE);
					dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
					dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
					dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
					//m_rgbIDColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
					//m_rgbDescColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
				}
				else
				{
					dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
				}
				//Autosizing Drop List
				if(m_nMaxDropListWidth ==0 )
					m_nMaxDropListWidth = GetDroppedWidth();
				SIZE sz;
				GetTextExtentPoint32(dc.GetSafeHdc(),m_csMaxWidthCombined,m_csMaxWidthCombined.GetLength(),&sz);
				if(m_nMaxDropListWidth < sz.cx )
				{
					m_nMaxDropListWidth = sz.cx;
					SetDroppedWidth(m_nMaxDropListWidth+50);
				}
				
				//Reset old settings
				dc.SetTextColor(crOldTextColor);
				dc.SetBkColor(crOldBkColor);
				dc.Detach();
			}
		}
		// Intial or Empty conditions
		if (GetCount() == 0 || lpDrawItemStruct->itemID > (unsigned int)GetCount()) 
			return;
		if((lpDrawItemStruct->itemID ==0) && lpDrawItemStruct->itemData == NULL)
		{
			CDC dc;
			if(dc.Attach(lpDrawItemStruct->hDC))
			{
				// Bakckup old settings
				COLORREF crOldTextColor = dc.GetTextColor();
				COLORREF crOldBkColor = dc.GetBkColor();
 
				if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
					(lpDrawItemStruct->itemState & ODS_SELECTED))
				{
					dc.SetBkMode(OPAQUE);
					dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
					dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
					dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
					//m_rgbIDColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
					//m_rgbDescColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
				}
				else
				{
					dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
				}
				//Autosizing Drop List
				if(m_nMaxDropListWidth ==0 )
					m_nMaxDropListWidth = GetDroppedWidth();
				SIZE sz;
				GetTextExtentPoint32(dc.GetSafeHdc(),m_csMaxWidthCombined,m_csMaxWidthCombined.GetLength(),&sz);
				if(m_nMaxDropListWidth < sz.cx )
				{
					m_nMaxDropListWidth = sz.cx;
					SetDroppedWidth(m_nMaxDropListWidth+50);
				}
				//Reset old settings
				dc.SetTextColor(crOldTextColor);
				dc.SetBkColor(crOldBkColor);
				dc.Detach();
				return;
			}
		}
		if (lpDrawItemStruct->itemData == NULL)
			return;
		else
		{
			//Display Item Implementation
			ComboBoxItemData* pItemData = NULL;
			pItemData = (ComboBoxItemData *)lpDrawItemStruct->itemData;
			CDC dc;
			if(dc.Attach(lpDrawItemStruct->hDC))
			{	
				// Calculate Autosize
				SIZE Size;
				int nMaxWidth;
				CPen* pOldPen;
 
				//Autosizing Drop List
				if(m_nMaxDropListWidth ==0 )
					m_nMaxDropListWidth = GetDroppedWidth();
				SIZE sz;
				GetTextExtentPoint32(dc.GetSafeHdc(),m_csMaxWidthCombined,m_csMaxWidthCombined.GetLength(),&sz);
				if(m_nMaxDropListWidth < sz.cx )
				{
					m_nMaxDropListWidth = sz.cx;
					SetDroppedWidth(m_nMaxDropListWidth+50);
				}
 

				if(m_bAutoAlign)
				{
					GetTextExtentPoint32(dc.GetSafeHdc(),m_MaxLengthData,m_MaxLengthData.GetLength(),&Size);
					nMaxWidth = Size.cx;
					//CString cs;cs.Format("\n %s - %d",m_MaxLengthData,nMaxWidth);
					//OutputDebugString(cs);
				}
				else
				{
					nMaxWidth = 0;
				}
				// Bakckup old settings
				COLORREF crOldTextColor = dc.GetTextColor();
				COLORREF crOldBkColor = dc.GetBkColor();
 
				// Item Highlight
				if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
					(lpDrawItemStruct->itemState & ODS_SELECTED))
				{
					dc.SetBkMode(OPAQUE);
					dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
					dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
					dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
					m_rgbIDColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
					m_rgbDescColor = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
				}
				else
				{
					dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
					m_rgbIDColor = ::GetSysColor(COLOR_MENUTEXT);
					m_rgbDescColor = ::GetSysColor(COLOR_MENUTEXT);
				}
				// Drawing All Items
				if(lpDrawItemStruct->itemAction >= 0x1)
				{
					
					CRect rect(lpDrawItemStruct->rcItem);
					rect.DeflateRect(1,0);
					CRect rc(rect);
					COLORREF cr;
 
					
 
					// Drawing ID Value
					rc.left +=1;
					rc.bottom -=1;
					cr = dc.SetTextColor(m_rgbIDColor);
					dc.DrawText(pItemData->cs_ID, -1, &rc, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
					dc.SetTextColor(cr);
 
					// Drawing Mask Value
					if(	m_bAutoAlign && GetDroppedState())
					{
						rc.left = nMaxWidth + 10;
					}
					else
					{
						GetTextExtentPoint32(dc.GetSafeHdc(),pItemData->cs_ID,pItemData->cs_ID.GetLength(),&Size);
						rc.left = Size.cx + 10;
					}
					if(!pItemData->cs_ID.IsEmpty())
					{
						if((m_MaskChar == "" || m_MaskChar.IsEmpty()))
						{
							CPen maskStyle(PS_SOLID, 0, m_rgbMaskColor);
							pOldPen = dc.SelectObject(&maskStyle);
							dc.MoveTo(rc.left,rc.top);
							dc.LineTo(rc.left,rc.bottom+1);
							dc.SelectObject(pOldPen);
							rc.left +=2;
						}
						else
						{
							COLORREF cr = dc.SetTextColor(m_rgbMaskColor);
							dc.DrawText(m_MaskChar, &rc, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
							dc.SetTextColor(cr);
							rc.left +=2;
						}
					}
					//Drawing Description Value
					rc.left += 3;
 
					cr = dc.SetTextColor(m_rgbDescColor);
					dc.DrawText(pItemData->cs_Desc , -1, &rc, DT_LEFT|DT_SINGLELINE|DT_VCENTER);
					dc.SetTextColor(cr);
					
					if(lpDrawItemStruct->itemState != 0x11 && lpDrawItemStruct->itemState !=0x1000 && 
						lpDrawItemStruct->itemState !=0x1300 ) //Show Mask Char only
					{
						CPen linePen(PS_SOLID, 0, m_rgbBorderColor);
						CRect ct = CRect(lpDrawItemStruct->rcItem);
						pOldPen = dc.SelectObject(&linePen);
						dc.MoveTo(ct.left,ct.bottom);
						dc.LineTo(ct.right,ct.bottom);
 
						dc.MoveTo(ct.left,ct.top);
						dc.LineTo(ct.right,ct.top);
 
						dc.SelectObject(pOldPen);
					}
				}
				//Reset old settings
				dc.SetTextColor(crOldTextColor);
				dc.SetBkColor(crOldBkColor);
				dc.Detach();
			}
		}
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
	catch( ... )
	{
	}
}
int CMaskedComboBox::AddString(CString csString)
{
	int nRet = -1;
	try
	{
		if(m_MaxLengthData.GetLength() >= csString.GetLength())	
			m_MaxLengthData = csString;
		if(m_csMaxWidthCombined.GetLength() <= csString.GetLength())
				m_csMaxWidthCombined = csString;
		nRet = CComboBox::AddString(csString.GetBuffer(csString.GetLength()));
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
	catch( ... )
	{
	}
	return nRet;
}
int CMaskedComboBox::AddCode(CString csID, CString csDesc, int nIntData)
{
	int nIndex = -1;
	try
	{
		//if(csID == CString("") || csID.IsEmpty())
		//{
		//	nIndex =-1;
		//}
		//else
		{
			if(m_MaxLengthData.GetLength() <= csID.GetLength())	
				m_MaxLengthData = csID;
			if(m_csMaxWidthCombined.GetLength() <= csID.GetLength() + csDesc.GetLength())
				m_csMaxWidthCombined = csID + csDesc;
 
			nIndex=CComboBox::AddString(csID.GetBuffer(csID.GetLength()));
			switch(nIndex)
			{
				case CB_ERRSPACE: 
				case CB_ERR: 
					nIndex = -1; 
					break;
				default:
					ComboBoxItemData *pItemData = new ComboBoxItemData();
					m_pDataList.AddTail(pItemData);
					pItemData->cs_ID = csID;
					pItemData->cs_Desc = csDesc;
					pItemData->nIntData = nIntData;
					CComboBox::SetItemDataPtr(nIndex,pItemData);
			}
		}
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
	catch( ... )
	{
	}
	return nIndex;
}
CString CMaskedComboBox::GetCode(int nIndex, int nWhichCode) const
{
	CString csRet="";
	try
	{
		switch(nIndex)
		{
			case CB_ERR: 
				break;//safe Break
			default:
				switch(nWhichCode)
				{
					case 1:	csRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->cs_ID;break;
					case 2:	csRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->cs_Desc;break;
					default: csRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->cs_ID;
				}
		}
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
	catch( ... )
	{
	}
	return csRet;
}
int CMaskedComboBox::GetIntCode(int nIndex) const
{
	int nRet = -1;
	try
	{
		switch(nIndex)
		{
			case CB_ERR: 
				nRet = -1;
				break;//safe Break
			default:
				nRet = ((ComboBoxItemData *)CComboBox::GetItemDataPtr(nIndex))->nIntData;
		}
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
	catch( ... )
	{
	}
	return nRet;
}
CString CMaskedComboBox::GetID(int nIndex) const
{
	return GetCode(nIndex);
}
CString CMaskedComboBox::GetCurSelectedID() const
{
	int nIndex = GetCurSel();
	return GetCode(nIndex);
}
CString CMaskedComboBox::GetDesc(int nIndex) const
{
	return GetCode(nIndex,2);
}
CString CMaskedComboBox::GetCurSelectedDesc() const
{
	int nIndex = GetCurSel();
	return GetCode(nIndex,2);
}
int CMaskedComboBox::GetIntData(int nIndex) const
{
	return GetIntCode(nIndex);
}
int CMaskedComboBox::GetCurSelectedIntData() const
{
	int nIndex = GetCurSel();
	return GetIntCode(nIndex);
}
void CMaskedComboBox::_DumpMemory()
{
	try
	{
		while( !m_pDataList.IsEmpty() )
		{
			ComboBoxItemData * pDumpData = m_pDataList.RemoveHead();
			try //very safe
			{
				if(pDumpData != NULL) 
				{
			   	   delete pDumpData;
				}
			}
			catch( ... ) 
			{
			} //continue next
		}
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
}
void CMaskedComboBox::Cleanup()
{
	_DumpMemory();
	CComboBox::ResetContent();
	CComboBox::Clear();
	m_MaxLengthData = "";
}
int CMaskedComboBox::DeleteCode(int nIndex)
{
	int nRet = -1;
	try
	{
		int nCount = CComboBox::GetCount();
		if(nCount <= 0) return -1;
		
		if(nIndex >=0 && nIndex < GetCount())
		{
			delete  (ComboBoxItemData *)(CComboBox::GetItemDataPtr(nIndex));
		}
		nRet = CComboBox::DeleteString(nIndex);
		CWnd::Invalidate();
	}
	catch( CMemoryException* e )
	{
	   e->Delete();
	}
	catch( CFileException* e )
	{
	   e->Delete();
	}
	catch( CException* e )
	{
	   e->Delete();
	}
	catch( ... )
	{
	}
	return nRet;
}
void CMaskedComboBox::ResetContent()
{
	Cleanup();
}
void CMaskedComboBox::DeleteAll()
{
	Cleanup();
}
void CMaskedComboBox::Clear()
{
	Cleanup();
}
void CMaskedComboBox::CleanUp()
{
	Cleanup();
}
BOOL CMaskedComboBox::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message == WM_CHAR)
	{
		try
		{
			if(pMsg->wParam == 0x3) //CTRL + C
			{
				CString csClipData = this->GetCurSelectedID()+" | "+this->GetCurSelectedDesc();
				if (OpenClipboard())
				{
					EmptyClipboard();
					HGLOBAL hClipboardData;
					hClipboardData = GlobalAlloc(GMEM_DDESHARE,csClipData.GetLength()+1);
					char * pchData;
					pchData = (char*)GlobalLock(hClipboardData);
					strcpy(pchData, LPCSTR(csClipData));
					GlobalUnlock(hClipboardData);
					SetClipboardData(CF_TEXT,hClipboardData);
					CloseClipboard();
				}
			}
			else if (!GetDroppedState() && pMsg->wParam != VK_RETURN && pMsg->wParam != VK_ESCAPE )
				ShowDropDown(); 
		}
		catch( CMemoryException* e )
		{
		   e->Delete();
		}
		catch( CFileException* e )
		{
		   e->Delete();
		}
		catch( CException* e )
		{
		   e->Delete();
		}
		catch( ... )
		{
		}
	}
	return CComboBox::PreTranslateMessage(pMsg);  	
}
 
MaskedComboBox.h
 
#if !defined(AFX_MASKEDCOMBOBOX_H__32482D69_64C2_4FFF_8820_E4AEB41E83EE__INCLUDED_)
#define AFX_MASKEDCOMBOBOX_H__32482D69_64C2_4FFF_8820_E4AEB41E83EE__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>

 
// MaskedComboBox.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMaskedComboBox window
struct ComboBoxItemData
{
	CString cs_ID;
	CString cs_Desc;
	int nIntData;
	ComboBoxItemData()
	{
		cs_ID="";
		cs_Desc="";
		nIntData=-1;
	}
	~ComboBoxItemData()
	{
	#ifdef _DEBUG		
		OutputDebugString("\nDumping Memory - "+cs_ID+"\n");
	#endif
		cs_ID.ReleaseBuffer();
		cs_Desc.ReleaseBuffer();
	}
};
class CMaskedComboBox : public CComboBox
{
// Construction
public:
	CMaskedComboBox();
	CMaskedComboBox(char MaskChar);
	CMaskedComboBox(CString csMaskChar);
// Attributes
public:
	CList <ComboBoxItemData * , ComboBoxItemData*> m_pDataList;
// Operations
public:
 
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMaskedComboBox)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL
// Implementation
public:
	void CleanUp();
	COLORREF m_rgbDescColor;
	COLORREF m_rgbIDColor;
	COLORREF m_rgbBorderColor;
	COLORREF m_rgbMaskColor;
	bool m_bAutoAlign;
	int AddString(CString csString);
	void Clear();
	void Cleanup();
	void ResetContent();
	void DeleteAll();
	int DeleteCode(int Index);
	CString GetID(int nIndex) const;
	CString GetDesc(int nIndex) const;
	CString GetCurSelectedID() const;
	CString GetCurSelectedDesc() const;
	int GetIntData(int nIndex) const;
	int GetIntCode(int nIndex) const;
	int GetCurSelectedIntData() const;
	int AddCode(CString csID,CString csDesc,int nIntData = -1);
	CString GetCode(int nIndex,int nWhichCode = 1) const;
	CString m_csMaxWidthCombined;
	virtual ~CMaskedComboBox();
protected:
	int m_nMaxDropListWidth;
	void _DumpMemory();
	CString m_MaxLengthData;
	CString m_MaskChar;
// Generated message map functions
	//{{AFX_MSG(CMaskedComboBox)
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	//}}AFX_MSG
	virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
 
	DECLARE_MESSAGE_MAP()
};
 
/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MASKEDCOMBOBOX_H__32482D69_64C2_4FFF_8820_E4AEB41E83EE__INCLUDED_)

 

Feel free to enter your comments for the above implemetation Cool | :cool:
S.V.Rajkumar

SuggestionAuto Sizing - Columns PinmemberRAJKUMARV15-Mar-12 21:04 
QuestionWhat finally made this work for me. Pinmemberbramoin9-Mar-12 11:48 
QuestionLicense? Pinmembercmconti13-Jul-11 8:22 
QuestionCombo-box's dropdown button color? Pinmemberddas-edEN23-Jul-08 23:36 
QuestionDoes it work in a DLL? PinmemberVictor Monteverde9-Nov-07 9:18 
AnswerNevermind - WM_DRAWITEM PinmemberVictor Monteverde12-Nov-07 7:02 
GeneralDon't work in Vs 2005 PinmemberFilippoCSM6-Nov-07 2:31 
QuestionGetOrCreateItemData Bug [modified] Pinmemberforkit29-Oct-07 14:52 
GeneralErrors compiling with VS2005 PinmemberC++ Hacker2-May-07 22:44 
GeneralRe: Errors compiling with VS2005 Pinmemberforkit31-Oct-07 4:05 
GeneralRe: Errors compiling with VS2005 PinmemberC++ Hacker11-Nov-07 22:03 
Question.Net? PinmemberMember #247019224-Jan-07 5:17 
GeneralAdded functionality: disabled items Pinmemberpatrickp16-Jan-07 5:44 
GeneralRe: Added functionality: disabled items Pinmemberronhash29-Jan-07 9:11 
QuestionBackground color PinmemberTheIronFist12-Dec-06 10:33 
AnswerRe: Background color PinmemberTheIronFist29-Dec-06 1:15 
GeneralRe: Background color Pinmemberronhash29-Jan-07 9:13 
QuestionDrop-down button color Pinmemberddas-edEN23-Jul-08 23:34 
QuestionCombobox is 3 pixels bigger in height than normal? PinmemberFuzzychaos29-Oct-06 9:23 
AnswerRe: Combobox is 3 pixels bigger in height than normal? Pinmemberronhash29-Oct-06 15:16 
AnswerRe: Combobox is 3 pixels bigger in height than normal? PinmemberFuzzychaos30-Oct-06 15:13 
GeneralInital value shown in super combor box Pinmemberdoctorrie9-Apr-06 15:10 
GeneralRe: Inital value shown in super combor box Pinmemberronhash20-Apr-06 13:20 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 13 Apr 2004
Article Copyright 2004 by ronhash
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid