Professional UI Solutions
Site Map   /  Register


Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Prevent change in cell that is being edited Collapse All
Subject Author Date
Finn Arildsen Dec 5, 2006 - 3:26 PM

I would like to decide if I should accept the change that a user is doing to the contents of a cell in a grid when editing. Is there a way to tell the cell that the change should be rejected and the original contents restored, or do I need to reinstate the contents myself?

Thanks in advance

Finn Arildsen

Suhai Gyorgy Dec 6, 2006 - 2:03 AM

There are CExtGridWnd::OnGridCellInplaceControlTextInputComplete and CExtGridWnd::OnGridCellInplaceControlTextInputVerify methods for this purpose. The first one can be used when you want to reject the change at the end of the editing, the second can be used to check the content during editing. The first method’s last parameter is a bool bSaveChange which has to be set to false when you want the change to be abandoned. The second method has to return false when you want to reject changes. Check Help-file for details.

Finn Arildsen Dec 6, 2006 - 10:06 AM

I can see that if I assign false to bSaveChange from inside my grids OnGridCellInplaceControlTextInputComplete, this has the effect that OnGridCellInputComplete doesn’t get called, but this does not have the effect that the text reverts to the original text, in the same way as it happens if I hit Escape instead of Enter.

So, I don’t understand how I can use OnGridCellInplaceControlTextInputComplete to reject a change?

Suhai Gyorgy Dec 6, 2006 - 1:27 PM

I tried this one, it worked fine for me in a CExtGridWnd derived class:

	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 ( bEndEdit ) {
			if (/*someCondition*/ true) {
				sTextNew = sTextInitial;
				return true;
		return CExtGridWnd::OnGridCellInplaceControlTextInputVerify(
This reverts to the original text at the end of the editing.

Finn Arildsen Dec 6, 2006 - 1:43 PM

Yep, thanks, this works for me too.

Does this mean that your original proposed solution is not supposed to work after all? If no, what IS the intention with the bSaveChange parameter in the OnGridCellInplaceControlTextInputComplete method?

Suhai Gyorgy Dec 7, 2006 - 4:42 AM

You are right, I didn’t try out my original suggestion, just read through the Help. Sorry. It seems the intention of the parameter is not to set its value in the overriden method, but to check whether the editing is completed with enter or escape key. From Help: "bSaveChanges:
Indicates that the results of editing will be applied to the cell object if this argument is true; abandoned otherwise." So in your overriden method you should only make connected changes when bSaveChange is true.

I think in this case it works similar to the MFC overridables, as in this Note: "This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function."