Sets the editor to be used when editing a cell.
void SetCellComboList( int nRow, int nCol, LPCSTR lpcszComboList )
The examples in this section will use an existing grid dialog resource DLL that gets installed with Origin C's Developer Kit. The DLL can be found in this zip file, under \Dialog Builder\GridDLG sub-folder.
#include <..\Originlab\DialogEx.h> #include "GridDLGRes.h"// resource DLL header enum{ GRID_COUNTRY_COL = 0, GRID_CITY_COL, GRID_FLOWER_COL, GRID_SHIP_COL, GRID_ADDRESS_COL }; #define THE_COUNTRY_LIST "AUSTRALIA|CANADA|CHINA|JAPAN|UK|USA" #define AUSTRALIA_CITY_LIST "Melbourne|Perth|Sydney" #define CANADA_CITY_LIST "Montreal|Ottawa|Toronto|Vancouver" #define CHINA_CITY_LIST "Beijing|Guangzhou|Shanghai|Shenzhen" #define JAPAN_CITY_LIST "Nagoya|Osaka|Sapporo|Tokyo|Yokohama" #define UK_CITY_LIST "Birmingham|Liverpool|London|Manchester" #define USA_CITY_LIST "Boston|Chicago|Los Angeles|New York|San Francisco" class GridCtrlDLG : public ResizeDialog { public: GridCtrlDLG() : ResizeDialog(IDD_GRID_DLG, "GridDLG") { } int DoModal(HWND hParent = NULL) { InitMsgMap(); int nRet = ResizeDialog::DoModal(hParent); return nRet; } protected: ///----------------- Message Map ---------------- EVENTS_BEGIN ON_INIT(OnInitDialog) ON_SIZE(OnDlgResize) ON_GETMINMAXINFO(OnMinMaxInfo) ON_GRID_AFTER_EDIT(IDC_GRID, OnGridComboChange) ON_GRID_BUTTON_CLICK(IDC_GRID, OnGridButtonClick) ON_OK(OnOK) EVENTS_END ///---------------------------------------------- BOOL OnInitDialog() { ResizeDialog::OnInitDialog(0, "Grid Dialog"); initGrid(); fitDlgWidthtoGrid(); SetInitReady(); return TRUE; } BOOL OnDlgResize(int nType, int cx, int cy) { if(!IsInitReady()) return TRUE; uint nButtonIDs[] = {IDOK, 0}; ArrangeMainItemAndControls(nButtonIDs, IDC_GRID, NULL, false); return TRUE; } void OnGridComboChange(Control flxControl, int nRow, int nCol) { if(GRID_COUNTRY_COL == nCol) { string strCountry = m_GridCtrl.GetCell(nRow, nCol); string strCountryList = THE_COUNTRY_LIST; string strCityList; int nCountry = strCountryList.FindToken(strCountry, ITEM_SEPARATOR); switch(nCountry) { case 0: strCityList = AUSTRALIA_CITY_LIST; break; case 1: strCityList = CANADA_CITY_LIST; break; case 2: strCityList = CHINA_CITY_LIST; break; case 3: strCityList = JAPAN_CITY_LIST; break; case 4: strCityList = UK_CITY_LIST; break; case 5: strCityList = USA_CITY_LIST; break; default: return; } m_GridCtrl.SetCellComboList(nRow, GRID_CITY_COL, strCityList); string strCity = m_GridCtrl.GetCell(nRow, GRID_CITY_COL); if(strCityList.FindToken(strCity, ITEM_SEPARATOR) < 0) { strCity = strCityList.GetToken(0, ITEM_SEPARATOR); m_GridCtrl.SetCell(nRow, GRID_CITY_COL, strCity); } } } void OnGridButtonClick(Control flxControl, int nRow, int nCol) { if(GRID_FLOWER_COL == nCol) { RECT rect; m_GridCtrl.GetCellRect(nRow, nCol, rect, true, true); Menu menuFlower; int nCmd = 1; menuFlower.Add("Iris", nCmd++, MF_STRING); menuFlower.Add("Jasmine", nCmd++, MF_STRING); menuFlower.Add("Lily", nCmd++, MF_STRING); menuFlower.Add("Peony", nCmd++, MF_STRING); menuFlower.Add("Rose", nCmd++, MF_STRING); nCmd = 0; menuFlower.TrackPopupMenu(0, rect.right, rect.top, GetSafeHwnd(), &nCmd); if(nCmd) { string strFlower; menuFlower.GetMenuString(nCmd, strFlower, MF_BYCOMMAND); m_GridCtrl.SetCell(nRow, nCol, strFlower); } } } BOOL OnOK() { int nFlag = 0; for(int ii = m_GridCtrl.GetRowOffset(); ii < m_GridCtrl.GetRows(); ii++) { vector<string> vsValues; m_GridCtrl.GetRowValues(ii, vsValues); string strCheck = str_combine(vsValues, ""); strCheck.TrimRight(); if( strCheck.IsEmpty() ) continue; if( !nFlag ) { nFlag++; vector<string> vsTitles; m_GridCtrl.GetRowValues(0, vsTitles); out_str( str_combine(vsTitles, "\t") ); } out_str( str_combine(vsValues, "\t") ); } return TRUE; } private: void initGrid() { m_GridCtrl.Init(IDC_GRID, *this); m_GridCtrl.SetupRowsCols( 1, 0, 5, 1 ); m_GridCtrl.SetColheader("Country|City|Flower|Ship|Address"); m_GridCtrl.SetColWidth(GRID_COUNTRY_COL, 1500); m_GridCtrl.SetColWidth(GRID_CITY_COL, 1500); m_GridCtrl.SetColWidth(GRID_FLOWER_COL, 1500); m_GridCtrl.SetColWidth(GRID_SHIP_COL, 450); m_GridCtrl.SetColWidth(GRID_ADDRESS_COL, 2000); //move grid control to top left RECT rrList; rrList.top = rrList.left = GetControlGap(); m_GridCtrl.MoveWindow(rrList); m_GridCtrl.SetColComboList(GRID_COUNTRY_COL, THE_COUNTRY_LIST); m_GridCtrl.SetColComboList(GRID_FLOWER_COL, "|..."); HINSTANCE hInst = NULL; int nResId = OBM_RGARROW; HBITMAP hBmp = LoadBitmap(hInst, (LPCSTR)nResId); PictureHolder pict; if(pict.CreateFromBitmap(hBmp, TRUE)) m_GridCtrl.SetColDotButtonIcon(GRID_FLOWER_COL, pict); m_GridCtrl.SetColDataType(GRID_SHIP_COL, flexDTBoolean); m_GridCtrl.SetColAlignment(GRID_SHIP_COL, flexAlignCenterCenter); } int getColsWidth() { int nTotal; for(int nCol = m_GridCtrl.GetCols()-1; nCol >= 0; nCol--) { nTotal += m_GridCtrl.TwipsToPixels( m_GridCtrl.GetColWidth(nCol) ); } return nTotal; } void fitDlgWidthtoGrid() { RECT rrDlg; m_wndDlg.GetWindowRect(&rrDlg); rrDlg.right = rrDlg.left + getColsWidth() + GetControlGap() * 2 + 100; DisableOnSize(true); m_wndDlg.MoveWindow(&rrDlg); DisableOnSize(false); } private: GridControl m_GridCtrl; }; bool OpenGridDLG() { GridCtrlDLG myDlg; myDlg.DoModal( GetWindow() ); return true; }
GridControl.h