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 » Quick PropertyGrid question Collapse All
Subject Author Date
Michael Valentine Dec 6, 2005 - 8:08 AM

Hi,


I need to programmatically expand/collapse items in my property grid. I am doing so in the following way:


 


CExtPropertyCategory* pCat = new CExtPropertyCategory("Test");


VERIFY(PropertyStore()->ItemInsert(pCat);


pCat->ExpandedSet(bExpanded);


 


This seems to work, however if I then click on subitems of this category I get the following assert:


ASSERT( m_nContentWeightExpanded >= nWeight );


This i

Michael Valentine Dec 6, 2005 - 8:29 AM

Sorry the formatting is all messed up there, it looked fine in the preview! The assert is occuring in line 96 of exttreegridwnd.cpp. I am also calling PropertyStoreSynchronize and RecalcLayout functions after adding my items.

Technical Support Dec 7, 2005 - 2:22 AM

The CExtPropertyGridCtrl window contains one or more tree grid windows which are instances of the CExtPropertyGridWnd-derived classes. By default, there are two grid windows created: the CExtPropertyGridWndCategorized and CExtPropertyGridWndSorted windows. Each of them contains tree items that correspond to the property items in the property store. By default, the CExtPropertyGridWndCategorized window contains all the property values and property categories and the CExtPropertyGridWndSorted window contains only property values and no property categories. Your code should assume that each tree window may or may not contain any property item from the property store. So, traverse all the tree grid windows, find >HTREEITEM lines corresponding to the property category, and expand/collapse them if needed:

bool bExpand = true; // or false
CExtPropertyCategory * pPropertyCategory = . . .
CExtPropertyGridCtrl & wndPGC = . . . 
CTypedPtrArray < CPtrArray, CExtPropertyGridWnd * > arrGrids;
    wndPGC.OnPgcQueryGrids( arrGrids );
INT nGridIdx = 0;
 for( ; nGridIdx < arrGrids.GetSize(); nGridIdx ++ )
 {
    CExtPropertyGridWnd * pGrid = arrGrids[ nGridIdx ];
    ASSERT_VALID( pGrid );
    HTREEITEM hTreeItem =
        pGrid->PropertyItemToTreeItem(
            pPropertyCategory
            );
    if( hTreeItem == NULL )
        continue;
    pGrid->ItemExpand(
        hTreeItem,
        bExpand ? TVE_EXPAND : TVE_COLLAPSE
        );
 } // for( ; nGridIdx < arrGrids.GetSize(); nGridIdx ++ )


Michael Valentine Dec 7, 2005 - 3:47 AM

Thanks for your answer but I found that it only works for items that are at the root level, i.e. it is not recursive and hence I still get the same assert. However I realise now that the problem is that I needed to set all of the child items to be collapsed if their parent is. Calling the following code on the item to expand/collapse seemed to do the trick:


void CPropertyGridCtrl::ExpandItem(CExtPropertyItem* pItem, bool expand)
{
 for (int i=0;i<pItem->ItemGetCount();i++)
 {
  CExtPropertyItem* pChildItem = pItem->ItemGetAt(i);
  ExpandItem(pChildItem, expand);
 }


 pItem->ExpandedSet(expand);
}

Technical Support Dec 7, 2005 - 9:52 AM

We have carefully checked the CExtTreeGridWnd class item expanding code and not found the problem with visible item offset calculation. We would appreciate if you send us any test project with the CExtPropertyGridCtrl window where this assertion persists.

Michael Valentine Dec 8, 2005 - 2:56 AM

Ok, I have sent you some code...