如何保持更新之间的树形控件扩展 [英] How to maintain tree control expansion between updates

查看:63
本文介绍了如何保持更新之间的树形控件扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个树控件(CTreeCtrl),可以通过GUI更新.更改后对其进行更新时,树视图将折叠.我知道我可以使用Expand()方法,但这将扩展每个项目.有没有一种简单的方法可以仅扩展在更新之前已扩展的项目.还是我必须在更新之前保存扩展的HTREEITEMS列表,然后使用此信息仅对该列表中的项调用Expand方法?

I have a tree control (CTreeCtrl) tha gets updated via the GUI. When it is updated after a change, the tree-view is collapsed. I know I could use the Expand() method, but this will expand every item. Is there a simple way to expand only the items that were expanded before the update. Or will I have to save a list of expanded HTREEITEMS before the update, then use this information to only call the Expand method for the items in this list?

推荐答案

如果您需要清除并重新填充每个更新的树,然后必须保存状态.

相反,如果您动态添加和删除控件中的项目,则不会出现此问题.

为了获得这种行为,我将树控件中引用的对象映射回HTREEITEM.这样,当删除对象时,我可以在树控件中删除关联的项目.

具有此索引和反向索引的包装器类是维护此索引的简便方法.它可能具有以下数据成员和要添加和删除的功能.

If you are clearing and refilling the tree with every updated, then you will have to save the state.

If instead, you dynamically add and delete items from the control, then you won''t have this issue.

To get this behavior, I map objects that are referenced in the tree control, back to the HTREEITEM. This way, when the object is deleted, I can delete the associated item in the tree control.

A wrapper class with this index and a reverse index is an easy way to maintain this. It might have the following data members and functions to add and delete.

CTreeCtrl * pTreeCtrl;
std::map<HTREEITEM, void *> ItemToObjectMap;
std::map<void *, HTREEITEM> ObjectToItemMap;



此外,如果您的体系结构需要全面更新,则可以对照地图扫描更新后的元素.如果地图上缺少某个项目,请添加它.如果地图中没有更新项,请删除它.



Further, if your architecture requires a full update, you can scan the updated elements against your map. If an item is missing from the map add it. If the map has an item missing in your update, then delete it.


这篇关于如何保持更新之间的树形控件扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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