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 » CExtTreeGridWnd column sorting optimization Collapse All
Subject Author Date
Rado Manzela Jul 27, 2007 - 7:47 AM

I have CExtTreeGridWnd - derived view in my aplication. I’ve implemented sorting based on columns using recursive function which orders all items in tree by given column. The problem is that it seems to be very inefficient although when only one item has changed since last sort (also when no item is changed, only direction is reversed). I have about 200 main items, each containing few children. Sorting takes about 0.5 second which is too much because I need real-time sorting while some worker threads are updating some items and when I turn sorting on, CPU is going to 100% and program is practically unresponsible and very slow.

Do you have any idea how to make it faster?

This is what I do now: when worker updates data, it sends message to main thread which updates the tree grid and sorts the tree:

void UpdateTree()
{
CExtGridDataSortOrder so;
bool sorted = m_wndView.GridSortOrderGet(false,so);

.... UPDATE THE TREE (always 1 item)


if (sorted && !so.IsEmpty())
    {
        m_wndView.GridSortOrderSetup(false,so,false,false,false);
    }



Technical Support Jul 28, 2007 - 11:57 AM

The tree grid contains expanded/collapsed tree row branches. This requires a row mapping algorithm which makes only expanded row branches visible and scrollable in the tree grid window. The sorting algorithm in the tree grid often requires movement of many collapsed rows within one expanded when swapping of two rows is performed. This is the main reason why sorting in tree grid is slower than it is in the plain grid. Please try sorting only one child level of one parent item when your code modifies only one row cells.



Rado Manzela Jul 28, 2007 - 12:16 PM

I’ve optimized it. If somebody other is interested it seems ItemSortChildren() is not too good for recursive sortig because it is doing the same thing mutiple times.

Here is optimized function (working about 6 times faster for my tree):

void CChildView::SortRecursive(HTREEITEM item, const CExtGridDataSortOrder &_gdso,CExtTreeGridDataProvider & _DP)
{
    CExtTreeGridCellNode * pNode = CExtTreeGridCellNode::FromHTREEITEM( item );
    ASSERT_VALID( pNode );

    _DP.TreeNodeSortChildren( pNode, _gdso, this ) ;

    HTREEITEM sItem;

    for (sItem = ItemGetFirstChild(item); sItem; sItem = ItemGetNext(sItem,true,false,false))
    {
        if (ItemGetChildCount(sItem) < 2)
            continue;

        SortRecursive(sItem,_gdso,_DP);
    }
}

I’ve placed     OnSwUpdateScrollBars(); after calling recursive sort althoungt I’m not sure if it is necessary (sorting should not change number of visible items in tree, should it?).

Technical Support Jul 30, 2007 - 4:31 AM

The sorting in tree grid is much slower than in the plain grid. Yes, the OnSwUpdateScrollBars() method invocation is not needed after resorting because the number of items in the scrollable range does not chang. But you should invoke this method if you are using variable row heights in your tree grid. In this case, the number of visible rows can be different before and after resorting and, as a result, the size of the thumb button on the vertical scroll bar should also become different. We also recommend you ensure visibility of the focused item after resorting.