You can do this by using only virtual methods of the CExtGridWnd
class. Thers is no need in coding any cell objects. Here is an editable version of the AdoRecordsetView sample. You can override the following virtual method to know whether the changes made during editing were commited or cancelled:
virtual void OnGridCellInplaceControlTextInputComplete(
CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
__EXT_MFC_SAFE_LPCTSTR sTextNew,
bool bSaveChanges
);
The
bSaveChanges
parameter indicates whether the result of editing was applied to the cell object. There are several type-specific input complete events that can be caught with these virtual methods:
virtual void OnGridCellInplaceControlDateTimeInputComplete(
CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
COleDateTime dtNew,
bool bSaveChanges
);
virtual void OnGridCellInplaceControlSliderInputComplete(
CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
INT nPosNew,
bool bSaveChanges
);
virtual void OnGridCellInplaceControlIPAddressInputComplete(
CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
DWORD dwIPAddressNew,
bool bSaveChanges
);
You can control the editing process with this method:
virtual bool OnGridCellInplaceControlTextInputVerify(
const CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
__EXT_MFC_SAFE_LPCTSTR sTextInitial,
__EXT_MFC_SAFE_LPCTSTR sTextPrevious,
CExtSafeString & sTextNew,
bool bEndEdit
);
If the
bEndEdit
parameter is
false,
then the method is invoked each time when the user changes text in the editor. If the
bEndEdit
parameter is
true,
the editing is complete and you can return
true
or
false
depending on whether you want to apply or cancel the results of editing. Of course, you can use this method when the editing is complete. There are also several type-specific methods of this kind:
virtual bool OnGridCellInplaceControlDateTimeInputVerify(
const CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
COleDateTime dtInitial,
COleDateTime dtPrevious,
COleDateTime & dtNew,
bool bEndEdit
);
virtual bool OnGridCellInplaceControlSliderInputVerify(
const CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
INT nPosInitial,
INT nPosPrevious,
INT & nPosNew,
bool bEndEdit
);
virtual bool OnGridCellInplaceControlIPAddressInputVerify(
const CExtGridCell & _cell,
HWND hWndInplaceControl,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
DWORD dwIPAddressInitial,
DWORD dwIPAddressPrevious,
DWORD & dwIPAddressNew,
bool bEndEdit
);
The following virtual method allows you to catch the event when editing begins:
virtual bool OnGbwBeginEdit(
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
const RECT & rcCellExtra,
const RECT & rcCell,
const RECT & rcInplaceControl,
bool bContinueMsgLoop = true
);