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 » Tree Walking Collapse All
Subject Author Date
Phil Davis Aug 25, 2006 - 6:26 PM

I have a CExtTreeGridWnd tree of an arbitrary number of nodes and children with potential grandchildren.
Portions of the tree may or may not be visible and portions may or may not be expanded.
All of the cells are of type CExtGridCellString.

At this point in the code there is no knowledge of the size or shape of the tree.

The only information is a pointer to the root node obtained by calling ItemGetRoot();

Please could you give me some code which will walk every node in the tree returning a pointer so the text in the cell may be modified.

Thanks

Technical Support Aug 26, 2006 - 7:18 AM

If the tree layout and depth is unknown, you can traverse all the tree items using the following recursive function:<pre>voidvoid WaCExtTreeGridWnddWnwndTreeTree, HTREEIhTreeItemParentrent = NULL )
{
ASSERT_VALIDwndTreeTree) );
hTreeItemParentrent == NULL )
{
hTreeItemParentrenwndTree.ItemGetRootRoot();
ASSEhTreeItemParentrent != NULL );
}
LnChildItemIndexndnChildItemCountounwndTree.ItemGetChildCountouhTreeItemParentrent );
fnChildItemIndexndex =nChildItemIndexndenChildItemCountounChildItemIndexndex ++ )
{
HTREEIhTreeItemChildhilwndTree.ItemGetChildAtldhTreeItemParentrenChildItemIndexndex );
ASSEhTreeItemChildhild != NULL );
LnColNoolNo = . . .
CExtGridCellCelpCellCelwndTree.ItemGetCellCehTreeItemChildhinColNoolNo, 0, RUNTIME_CLACExtGridCellStringring ) );
ASSERT_VALpCellCell );
pCellCeTextSettSet( . . . );
WawndTreeTrhTreeItemChildhild );
}
pre/pre>

Phil Davis Aug 26, 2006 - 7:44 AM

Thank you for the response, but could you please post that code fragment again as it appears to have not been encapsulated in the [pre>[/pre> formating and is illegible.

Thanks

Technical Support Aug 26, 2006 - 7:51 AM

We are sorry fo this typo. Here is the well-formatted code:

void Walk( CExtTreeGridWnd & wndTree, HTREEITEM hTreeItemParent = NULL )
{
    ASSERT_VALID( (&wndTree) );
    if( hTreeItemParent == NULL )
    {
        hTreeItemParent = wndTree.ItemGetRoot();
        ASSERT( hTreeItemParent != NULL );
    }
LONG nChildItemIndex, nChildItemCount = wndTree.ItemGetChildCount( hTreeItemParent );
    for( nChildItemIndex = 0; nChildItemIndex < nChildItemCount; nChildItemIndex ++ )
    {
        HTREEITEM hTreeItemChild = wndTree.ItemGetChildAt( hTreeItemParent, nChildItemIndex );
        ASSERT( hTreeItemChild != NULL );
        LONG nColNo = . . .
        CExtGridCell * pCell = wndTree.ItemGetCell( hTreeItemChild, nColNo, 0, RUNTIME_CLASS( CExtGridCellString ) );
        ASSERT_VALID( pCell );
        pCell->TextSet( . . . );
        Walk( wndTree, hTreeItemChild );
    }
}