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);