brightside90
brightside90

Reputation: 243

How to force CTreeCtrl not to scroll to the item when SelectItem function is called?

I have simple CTreeCtrl on my dialog. It has only two levels of depth, something like this:

Simple tree. Before selection

Imagine that the user clicked on "Third" node so it becomes selected, then he pushing on the button that is also on the dialog and executes next code:

// m_tree is a dialog-based class member of CTreeCtrl type 
HTREEITEM hItem = m_tree.GetSelectedItem();
if (hItem)
{
    hItem = m_tree.GetNextSiblingItem(hItem); 
    if (hItem)
    {
        m_tree.SelectItem(hItem);
    }
}

After that hItem, which label is "Fourth" in my sample, becomes visible at the bottom of tree control window:

Simple tree. After selection

How can I force tree control not to scroll down to selected item? I just want to select it and that's all.

Upvotes: 1

Views: 480

Answers (1)

VuVirt
VuVirt

Reputation: 1917

You can try calling EnsureVisible on the previously selected item. This might flicker though, so you may try using SetRedraw(FASLE) before making the new selection and EnsureVisible.

Upvotes: 2

Related Questions