Sets picture to given cell.
bool SetCellPicture( int nRow, int nCol, PictureHolder & pict )
true on successful or false on failure
This section describes how to drag and drop picture in grid control in Origin C.
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{ SPECIALL_CELL = 1, BITMAP_CELL = SPECIALL_CELL, PICT_CELL, ICON_CELL }; 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_COMPLETE_DRAG(IDC_GRID, OnDragDropFinish) EVENTS_END ///---------------------------------------------- BOOL OnInitDialog() { ResizeDialog::OnInitDialog(0, "Grid Dialog"); //initialize grid control m_GridCtrl.Init(IDC_GRID, *this); m_GridCtrl.SetupRowsCols( 0, 0, 5, 4 ); m_GridCtrl.SetDragCell(true); setSpecialCell(0, 0, BITMAP_CELL); setSpecialCell(0, 1, PICT_CELL); setSpecialCell(0, 2, ICON_CELL); m_GridCtrl.SetCell(0, 3, 12.5); //move grid control to top left RECT rrList; rrList.top = rrList.left = GetControlGap(); m_GridCtrl.MoveWindow(rrList); SetInitReady(); m_GridCtrl.SetRedraw(flexRDBuffered); 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 OnDragDropFinish(Control ctrl, int* pnAllowEffect) { int nDraggedRow, nDraggedCol, nDropRow, nDropCol; if( m_GridCtrl.GetDraggedCell(nDraggedRow, nDraggedCol, true) && m_GridCtrl.GetDropCell(nDropRow, nDropCol, true) ) { PictureHolder pictNULL; int nDataType = m_GridCtrl.GetCellData(nDraggedRow, nDraggedCol); if(nDataType >= SPECIALL_CELL) { setSpecialCell(nDropRow, nDropCol, nDataType); m_GridCtrl.SetCell(nDropRow, nDropCol, ""); } else { m_GridCtrl.SetCellPicture(nDropRow, nDropCol, pictNULL); m_GridCtrl.SetCell(nDropRow, nDropCol, m_GridCtrl.GetCell(nDraggedRow, nDraggedCol)); m_GridCtrl.SetCellData(nDropRow, nDropCol, 0); } m_GridCtrl.SetCellPicture(nDraggedRow, nDraggedCol, pictNULL); m_GridCtrl.SetCell(nDraggedRow, nDraggedCol, ""); m_GridCtrl.SetCellData(nDraggedRow, nDraggedCol, 0); } } private: void setSpecialCell(int nRow, int nCol, int nDataType) { bool bRet; switch(nDataType) { case BITMAP_CELL: bRet = m_GridCtrl.SetCellBitmap(nRow, nCol, OBM_UPARROW, 0); break; case PICT_CELL: PictureHolder pict; if( pict.Load(GetAppPath(TRUE)+"Happy2.bmp") ) bRet = m_GridCtrl.SetCellPicture(nRow, nCol, pict); break; case ICON_CELL: bRet = m_GridCtrl.SetCellIcon(nRow, nCol, IDR_WORKSHEETTYPE_V8, MODULE_ORIGIN); break; default: break; } if(bRet) m_GridCtrl.SetCellData(nRow, nCol, nDataType); } private: GridControl m_GridCtrl; }; bool OpenGridDLG() { GridCtrlDLG myDlg; myDlg.DoModal( GetWindow() ); return true; }
GridControl.h