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 » How I can handle button pressed event ? Collapse All
Subject Author Date
Ayubkhan Pathan Mar 24, 2007 - 4:48 AM

I my application I have created a cell as
            CExtGridCellString *pValue =
                STATIC_DOWNCAST(
                CExtGridCellString,
                ValueActiveGetByRTC( RUNTIME_CLASS(CExtGridCellString) )
                );
            pValue->TextSet(_T("Edit text"));
            pValue->ModifyStyle(__EGCS_BUTTON_ELLIPSIS);

This shows me botton along with edit control. I overloaded OnButtonPressed() as well as virtual bool OnClick() methods in my class. But these functions are not getting called even if I pressed the button.

Please suggess the solution.

Suhai Gyorgy Mar 24, 2007 - 8:04 AM

I needed to do the same, this is how my code looks like:
in .h file:

class CMyTextCell : public CExtGridCellString
{
public:
	DECLARE_SERIAL( CMyTextCell );
	IMPLEMENT_ExtGridCell_Clone( CMyTextCell, CExtGridCellString );
	CMyTextCell(
		CExtGridDataProvider * pDP = NULL
		);
	virtual void OnButtonPressed(
		CExtGridWnd & wndGrid,
		INT nButtonType,
		const RECT & rcCellExtra,
		const RECT & rcCell,
		LONG nVisibleColNo,
		LONG nVisibleRowNo,
		LONG nColNo,
		LONG nRowNo,
		INT nColType,
		INT nRowType
		);
};
In .cpp file
IMPLEMENT_SERIAL( CMyTextCell, CExtGridCellString, VERSIONABLE_SCHEMA|1 );
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
...
CMyTextCell::CMyTextCell( CExtGridDataProvider * pDP /* = NULL */ )
	: CExtGridCellString( pDP )
{}
 
void CMyTextCell::OnButtonPressed(
	CExtGridWnd & wndGrid,
	INT nButtonType,
	const RECT & rcCellExtra,
	const RECT & rcCell,
	LONG nVisibleColNo,
	LONG nVisibleRowNo,
	LONG nColNo,
	LONG nRowNo,
	INT nColType,
	INT nRowType
	)
{
	CExtGridCellString::OnButtonPressed(
		wndGrid,
		nButtonType,
		rcCellExtra,
		rcCell,
		nVisibleColNo,
		nVisibleRowNo,
		nColNo,
		nRowNo,
		nColType,
		nRowType
		);
	if ( nButtonType == __EBTT_ELLIPSIS ) {
		// do something here
		if (you changed the text by code) {
			wndGrid.OnGridCellInputComplete(
				this,
				nColNo,
				nRowNo,
				nColType,
				nRowType
				);
			wndGrid->SetRedraw(TRUE);
			wndGrid->RedrawWindow(NULL, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
		}
	}
}
Please note, it is very important to put the IMPLEMENT_SERIAL( . . . ) line of code to the top of the .cpp file before the declaration of the MFC’s debug version of the C++ new operator.

With this class, your code above changes like this:
	CMyTextCell *pValue =
		STATIC_DOWNCAST(
		CMyTextCell,
		ValueActiveGetByRTC( RUNTIME_CLASS(CMyTextCell) )
		);
	pValue->TextSet(_T("Edit text"));
	pValue->ModifyStyle(__EGCS_BUTTON_ELLIPSIS);