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 Tech Support » CExtGridCellUpDown range Collapse All
Subject Author Date
Nitesh Singh Oct 17, 2006 - 1:07 AM

Dear Support,


Is there a method to limit the range of values in the cell? Suppose I want a range of 0 to 10. And now if current value shown is 10 then If I further push the UP button then the value shoud become 0 (not 11, I want the button to be enabled even if the value is 10). Similarily if current value is 0 then after pressing DOWN button the value should become 10.

I found one article "How to set a range for the CExtGridCellUpDown cell?" but I think it does not fullfil my criteria.
Thank you.......

Technical Support Oct 17, 2006 - 11:07 AM

You can do this by overriding the CExtGridCellUpDown class. When the user clicks on the up or down part of the spin button or presses the up and down arrow key, the OnValueIncrement or OnValueDecrement virtual methods are called. They are called for incrementing or decrementing the cell value, so you can override them and implement you whatever you want.

Nitesh Singh Oct 18, 2006 - 3:01 AM

Thank you. That helped. But I wanted one more feature. Suppose the range is 1 to 10. Then if anyother value entered should not be taken. And the range can be changed too.

For that I am having two members m_nRangeUpper, m_nRangeLower and a function SetRange(int, int) in the derived class CMyGridCellUpDown: public CExtGridCellUpDown . In the constructor I am setting some values m_nRangeUpper = 1, m_nRangeLower = 100;
And function.......
HRESULT CMyGridCellUpDown::OnParseText(    __EXT_MFC_SAFE_LPCTSTR sText) const
{
    ASSERT_VALID( this );
    ASSERT( sText != NULL );
HRESULT hr = CExtGridCellUpDown::OnParseText( sText );
    if( hr != S_OK )
        return hr;
long lVal = _ttol( LPCTSTR(sText) );
    if( lVal < m_nRangeLower || lVal > m_nRangeUpper )
        return E_INVALIDARG;
    return S_OK;
}

and when I am going to use this class CMyGridCellUpDown. And calling SetRange( 1,5); then it sets the pValue pointer passed in function Apply( pValue); But next time when I am changing the text.. then m_nUpperValue becomes 100 again for the same pointer. Seems like you are creating a new CMyGridCellUpDown and assigning the same pointer... This is not helping me....

Please suggest me something. I have to call SetRange() funtion as the range can vary from object to object. (u have done something in GridCellUpDownColorPart... but there the range is stricty between 0 to 255)
thank you..

Technical Support Oct 18, 2006 - 8:36 AM

It seems you are using the property grid. In this case, the following details may be helpful.

Each CExtPropertyValue instance keeps two CExtGridCell objects: the active one and the initial one. The later is used for the reset operation. These objects never appear inside tree grids in the property grid control and are stored inside CExtPropertyValue only. Each tree grid window in the property grid control contains cloned copies of active grid cells in property values. That is why you faced different cell copies. When the editing is complete in some tree grid window, the property grid control assigns a new cell value to the active cell in the property value and to the all cells of this property value in other tree grid windows. In case of combined property stores, each property value is a reference to several simple property values and the result of editing is assigned to all the referenced property values. So, if you use your own grid cell class which contains its specific data members, then it is important to override the CExtGridCell::Assign() virtual method like as follows:

void CYourCell::Assign( const CExtGridCell & other )
{
    ASSERT_VALID( this );
    CBaseCell::Assign( other );
CYourCell * pCell =
        DYNAMIC_DOWNCAST(
            CYourCell,
            ( const_cast < CExtGridCell * > ( &other ) )
            );
    if( pCell != NULL )
    {
        // assign all the specific data members
    } // if( pCell != NULL )
    else
    {
        // clear all the specific data members
    } // else if( pCell != NULL )
}

Nitesh Singh Oct 19, 2006 - 5:05 AM

Thanks... Its workin.