|
|
|
|
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.
Subject |
Author |
Date |
|
Ivan Surzhenko
|
Dec 13, 2007 - 11:53 PM
|
Prof-UIS 2.80
I like create assertion of value in CExtGridCellUpDown. After searching for information about this I found thread "Setting a range to numeric cells" where you propose overriding of OnQueryEnabledDecrement() and OnQueryEnabledIncrement().
Next simple class has been created:
class CMyNumericClass : public CExtGridCellUpDown { public:
long minvalue; long maxvalue;
virtual bool OnQueryEnabledDecrement() const; virtual bool OnQueryEnabledIncrement() const; };
bool CMyNumericClass::OnQueryEnabledIncrement() const { ASSERT_VALID( this ); if( intVal >= maxvalue ) return false; return true; }
bool CMyNumericClass::OnQueryEnabledDecrement() const { ASSERT_VALID( this ); if( intVal <= minvalue ) return false; return true; }
so it methods don`t call when data has been changed(by pressing to the Up/Down button of component or Copy/Paste way). Where mistake?
|
|
Ivan Surzhenko
|
Dec 14, 2007 - 9:33 AM
|
|
|
Suhai Gyorgy
|
Dec 14, 2007 - 2:08 AM
|
You need some more additions to make it work. in .h file: class CMyNumericClass : public CExtGridCellUpDown
{
public:
DECLARE_SERIAL( CMyNumericClass );
IMPLEMENT_ExtGridCell_Clone( CMyNumericClass, CExtGridCellUpDown);
CMyNumericClass CExtGridDataProvider * pDP = NULL);
virtual void Assign( const CExtGridCell & other );
public:
long minvalue;
long maxvalue;
virtual bool OnQueryEnabledDecrement() const;
virtual bool OnQueryEnabledIncrement() const;
};
In .cpp file: ...
#include "Somefile.h"
IMPLEMENT_SERIAL( CMyNumericClass, CExtGridCellUpDown, VERSIONABLE_SCHEMA|1 );
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
...
CMyNumericClass::CMyNumericClass( CExtGridDataProvider * pDP /* = NULL */ )
: CExtGridCellUpDown( pDP )
, minvalue(0) // or something else
, maxvalue(0) // or something else
{
}
void CMyNumericClass::Assign( const CExtGridCell & other )
{
ASSERT_VALID( this );
CExtGridCellUpDown::Assign( other );
CMyNumericClass *pCell = DYNAMIC_DOWNCAST(CMyNumericClass, (&other));
if ( pCell != NULL ) {
minvalue = pCell->minvalue;
maxvalue = pCell->maxvalue;
}
}
bool CMyNumericClass::OnQueryEnabledIncrement() const
{
ASSERT_VALID( this );
if( intVal >= maxvalue )
return false;
return true;
}
bool CMyNumericClass::OnQueryEnabledDecrement() const
{
ASSERT_VALID( this );
if( intVal <= minvalue )
return false;
return true;
}
It’s important to have the Assign method implemented and to have IMPLEMENT_SERIAL macro above #ifdef _DEBUG block. When using the cell for the first time ( filling it ), you need to call GridCellGet(nColNo, nRowNo, 0, 0, RUNTIME_CLASS(CMyNumericClass)); to make sure your class is used.
|
|