更新 ObjectListView 中的图标
我在当前项目中使用 TreeListView (ObjectListView 的子类型)。列表中的每个项目都有一个图标,但图标可能会根据项目的状态而变化。例如,如果该项目是只读的,我想使用带有小锁符号的图标。
当项目首次添加到 TreeListView 时,图标会正确显示,但稍后当项目的状态更改时,图标不会更新。如何强制控件重新生成所有图标?
I'm using an TreeListView (a sub type of ObjectListView) in my current project. Each item in the list is given an icon, but the icon my vary depending on the state of the item. For example if the item is readonly I want to use an icon with a little lock symbol.
When the items are first added to the TreeListView the icons are show correctly, yet later when the state of an item changes the icons are not updating. How do I force the control to regenerate all the icons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于图标是在调用第一列的 ImageGetter 时获取的,并且通常仅在行重新生成时调用,因此您似乎可以简单地调用 BuildList 并强制重建所有行。不过,这可能会很昂贵,具体取决于复杂性和行数。
如果可能的话,更好的解决方案是在知道数据发生更改后立即调用
RefreshItem
或RefreshObject
。这要求您知道需要更新其图标的特定OLVListItem
(行),或者更改的基础模型对象(因此如果重建其关联的行,将导致图标不同)。Since the icon is gotten when the ImageGetter for the first column is called, and since that is only called typically when the rows regenerate, then it seems like you could simply call
BuildList
and force all rows to rebuild. This might be expensive, though, depending on the complexity and number of rows.A better solution, if possible, would be to call
RefreshItem
orRefreshObject
as soon as you know data has changed. This requires you to know either the specificOLVListItem
(rows) that need their icons updated, or the underlying model objects that changed (and thus would cause the icon to differ were its associated rows rebuilt).