CTreeCtrl 展开而不滚动 [英] CTreeCtrl Expand without scrolling

查看:60
本文介绍了CTreeCtrl 展开而不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 CTreeCtrl 中,当我展开一个不可见的节点时,控件会自动重新定位树以使展开的节点可见.有什么办法可以防止这种行为吗?

In my CTreeCtrl, when I expand a node which is not visible the control automatically repositions the tree to make the expanded node visible. Is there any way to prevent this behaviour?

用例:我有一个树,它正在从远程源异步加载项目,并且可能在很长一段时间内构建树的底部",目前在完成时跳转到每个节点的树行为是非常分散用户的注意力.

Use case: I have a tree which is loading items asynchronously from a remote source and may be building the 'bottom' of the tree for quite some time, and currently the tree behaviour of jumping to each node as it is completed is very distracting to the user.

当前的解决方法:

/******************************************************************************
 Expand an item while retaining the tree position
 ******************************************************************************/
void CFileOpenTreeView::ExpandWithoutJumping(HTREEITEM hItem)
{
    // This still flickers for some reason, but at least it doesn't jump
    LockWindowUpdate();
    HTREEITEM hFirstVisible = GetTreeCtrl().GetFirstVisibleItem();

    GetTreeCtrl().Expand(hItem, TVE_EXPAND);

    GetTreeCtrl().SelectSetFirstVisible(hFirstVisible);
    UnlockWindowUpdate();
    Invalidate();
}

推荐答案

要回答您的即时问题,您可以在填充控件时使用 CWnd::LockWindowUpdate() 关闭窗口刷新和 CWnd::UnlockWindowUpdate().

To answer your immediate question, you can turn off window refreshing while the control is being populated, using CWnd::LockWindowUpdate() and CWnd::UnlockWindowUpdate().

不过,总的来说,如果可以,您可能需要重新考虑您的策略.例如,您可以在不扩展父节点的情况下填充树中的子节点.

In general, though, if you can, you may want to rethink your strategy. For example, you can populate sub-nodes in the tree without expanding the parent nodes.

此外,在您描述的用例中,您可能希望仅在用户展开父节点时才考虑动态填充节点的子节点.

Also, in the use case you've described, you may want to look into dynamically populating the children of a node only when the parent node is expanded by the user.

这篇关于CTreeCtrl 展开而不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆