Professional UI Solutions
Site Map   /  Register
 
 

Forum

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 » Validation for values in a property grid Collapse All
Subject Author Date
Malcolm D Jul 4, 2007 - 10:51 PM

I was wonder the best way to do validation for property grid items. E.G. to check if the text entered is a valid string, or to limit the range of numeric values.

There seems to be some support for the text entered, by using TextSet or OnParseText, but this doesn’t apply for all cases.
I haven’t yet found a better way.
Is there one? If not if would be good if we could have one.

A virtual function ( in CExtGridCell for example ) that can be called to validate the value (and if it fails, then the value reverts to the previous value)
- this seems to be the simple solution I would be expecting. Do you think there is a better way?

Thanks

Technical Support Jan 21, 2008 - 2:45 AM

It works only when the user scrolls the value using the spin buttons. So this is by design. You should use CExtGridCell::OnInplaceControlTextInputVerify() for this as described in the current forum thread.

Bart Kampers Jan 18, 2008 - 7:54 AM

The solution described in the article "How to set a range for the CExtGridCellUpDown cell?" does not work when the user types a value in stead of using the spinbuttons.

Technical Support Jul 5, 2007 - 9:46 AM

If you need to limit the range of numeric values, you can use the solution described in this article: How to set a range for the CExtGridCellUpDown cell?. There are several virtual methods which allow you to entirely control the inplace edit.

- CExtGridCell::OnInplaceControlTextInputVerify() and CExtGridWnd::OnGridCellInplaceControlTextInputVerify() which called when the user is typing the text in the in-place editor. The methods return true if the text data has a valid format, otherwise false.

- CExtGridCell::OnParseText() which is called to parse the text specified by the sText parameter.

- CExtGridCell::OnInplaceControlPreTranslateMessage() which performs the message pre-translation for the in-place active editor and returns true if the message has been successfully filtered by the cell object.

Please take a look at these methods in the documentation. You can use them to implement custom parsing and filtering for the inplace editor.

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 the 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 OnGridCellInplaceControlDurationInputVerify(
	const CExtGridCell & _cell,
	HWND hWndInplaceControl,
	LONG nVisibleColNo,
	LONG nVisibleRowNo,
	LONG nColNo,
	LONG nRowNo,
	INT nColType,
	INT nRowType,
	COleDateTimeSpan dtSpanInitial,
	COleDateTimeSpan dtSpanPrevious,
	COleDateTimeSpan & dtSpanNew,
	bool bEndEdit
	);
virtual bool OnGridCellInplaceControlHotKeyInputVerify(
	const CExtGridCell & _cell,
	HWND hWndInplaceControl,
	LONG nVisibleColNo,
	LONG nVisibleRowNo,
	LONG nColNo,
	LONG nRowNo,
	INT nColType,
	INT nRowType,
	DWORD dwHotKeyInitial,
	DWORD dwHotKeyPrevious,
	DWORD & dwHotKeyNew,
	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
       );