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 » Problem with CExtGridCells in general Collapse All
Subject Author Date
Krustys Donuts Dec 20, 2005 - 12:05 PM

So I’ve subclassed CExtGridCellString, and when the cell is created, I want to call a member function in it to set some property. The idea is that when the cell is eventually clicked, I can access this exact property.

For example, I want to create a new DonutCell. When I create this DonutCell, I need to pass the DonutShop that created it. When this cell is clicked, the OnButtonPressed() method should be able to determine which shop created it.

When I step through my code, which looks like this:

DonutCell* pCell = DYNAMIC_DOWNCAST( DonutCell, ValueActiveGet());
pCell->SetDonutShop( "Krustys Donuts");


pCell is something like 0x4809578. When I click on the cell and hit my breakpoint in OnButtonPressed(), the this pointer is 0x481b968. Can you explain why it is that the active cell isn’t the same as the one that handles this message? I’m confused.

Krustys Donuts Dec 20, 2005 - 12:21 PM

Ah, my colleague told me that it’s probably because stores get combined. So when I click on that cell, I’m getting a cell from the combined store. So the question is, if cell contents are copied, why isn’t my member variable (a pointer) being copied as well?

Technical Support Dec 21, 2005 - 2:57 AM

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 the cloned copies of active grid cells in property values. That is why you faced different cell copies. When the editing is completed 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 using 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
        // like your did in constructor
    } // else if( pCell != NULL )
}


Krustys Donuts Dec 21, 2005 - 9:37 AM

Thanks! That worked great!