// ComboGridCtrl.cpp: implementation of the CComboGridCtrl class. // // This is a demo of how to override CGridCtrl in order to offer // other editing capabilities such as a drop down list // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ComboGridCtrl.h" #include "InPlaceList.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif BEGIN_MESSAGE_MAP(CComboGridCtrl, CGridCtrl) //{{AFX_MSG_MAP(CComboGridCtrl) //}}AFX_MSG_MAP END_MESSAGE_MAP() ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CComboGridCtrl::CComboGridCtrl() { m_comboBoxStyle=CBS_DROPDOWN; } CComboGridCtrl::~CComboGridCtrl() { for(int i=0;iCopy(comStr); m_comStrArray.Add(col); return TRUE; } BOOL CComboGridCtrl::SetItemText(int nRow, int nCol, LPCTSTR str) { int comIndex=IsColumnCombo(nCol); if(comIndex!=-1&&nRow>=GetFixedRowCount()) { BOOL bRet; COMBOCOL combocol=m_comStrArray.GetAt(comIndex); for(int i=0;iGetSize();i++) if(combocol.comStr->GetAt(i)==str) { bRet=CGridCtrl::SetItemText(nRow,nCol,str); break; } return bRet; }else return CGridCtrl::SetItemText(nRow,nCol,str); } int CComboGridCtrl::IsColumnCombo(int nCol) { int comIndex=-1; COMBOCOL combocol; for(int i=0;irow, pItem->col); if (!pCell) return FALSE; if (pItem->mask & GVIF_TEXT) { int comIndex=IsColumnCombo(pItem->col); BOOL bFind=FALSE; if(comIndex!=-1) { if(pItem->rowGetSize();i++) if(combocol.comStr->GetAt(i)==pItem->szText) { bFind=TRUE; } } } if(!bFind&&comIndex!=-1) return FALSE; else pCell->szText=pItem->szText; } if (pItem->mask & GVIF_PARAM) pCell->lParam = pItem->lParam; if (pItem->mask & GVIF_IMAGE) pCell->iImage = pItem->iImage; if (pItem->mask & GVIF_STATE) pCell->state = pItem->state; if (pItem->mask & GVIF_FORMAT) pCell->nFormat = pItem->nFormat; if (pItem->mask & GVIF_BKCLR) pCell->crBkClr = pItem->crBkClr; if (pItem->mask & GVIF_FGCLR) pCell->crFgClr = pItem->crFgClr; if (pItem->mask & GVIF_FONT) memcpy(&(pCell->lfFont), &(pItem->lfFont), sizeof(LOGFONT)); return TRUE; } //*************************************************** // set item text by combobox index //************************************************** BOOL CComboGridCtrl::SetComboItemText(int nRow, int nCol, int index) { int comIndex=IsColumnCombo(nCol); if(comIndex==-1) return FALSE; COMBOCOL combocol=m_comStrArray.GetAt(comIndex); if(index>=combocol.comStr->GetSize()) return FALSE; return CGridCtrl::SetItemText(nRow,nCol,combocol.comStr->GetAt(index)); } //******************************************************** // set combobox style //******************************************************** void CComboGridCtrl::SetComboBoxStyle(DWORD dwStyle) { m_comboBoxStyle=dwStyle; }