我如何填充在虚拟模式下一个ListView异步? [英] How do I populate a ListView in virtual mode asynchronously?

查看:315
本文介绍了我如何填充在虚拟模式下一个ListView异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ListView中显示从数据库中的记录 - 但是检索可能需要较长的时间。我可以用RetrieveVirtualItem告诉我需要一个新的ListViewItem时,添加一个虚拟项目,并开始恢复;但我该怎么跟唱片做当数据库返回呢?而ListView控件是VirtualMode我不能更新ListView的Items集合。有没有办法告诉ListView中重新加载的项目?或者,我可以只保留到ListViewItem的参考和填充呢?如果没有那些会的工作,怎么还可以做填充虚拟模式一个ListView异步?

I'd like to display records from our database in a listview - but retrieves can take a long time. I can use RetrieveVirtualItem to tell me when a new ListViewItem is needed, add a dummy item, and start a retrieve; but what do I do with the record when the database returns it? I can't update the ListView's Items collection while the ListView is in VirtualMode. Is there a way to tell the ListView to reload an item? Or can I just keep a reference to the ListViewItem and populate that? If neither of those would work, how else could I populate a ListView in virtual mode asynchronously?

推荐答案

在ListView控件需要更新您的RetrieveVirtualItem处理器将被调用。如果您的数据尚未公布,你不能等待,那么你将不得不创建一个虚拟项目(不处理RetrieveVirtualItem将抛出一个异常)。

Your RetrieveVirtualItem handler will be called when the ListView needs updating. If your data is not available yet and you cannot wait, then you will have to create a dummy item (not handling RetrieveVirtualItem will raise an exception).

一旦你的数据准备好,你可以将失效控制 - 这将再次调用RetrieveVirtualItem每个可见项目。作为一种替代整个控制无效,你可以控制哪些项目是通过使用ListView控件的RedrawItems方法,它在虚拟和普通模式的工作原理重绘:

Once your data is ready, you can invalidate the control - this will call RetrieveVirtualItem again for each of the visible items. As an alternative to invalidating the whole control, you can control which items are to be redrawn by using the RedrawItems method of the ListView control, which works in virtual and regular modes:

<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.redrawitems.aspx\">http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.redrawitems.aspx

这听起来像它可能是值得批量下载您的记录,如果是由于需要一段时间。另外,如果你的数据库操作是昂贵的,这是值得研究的缓存ListItems的(有你需要处理CacheVirtualItems事件):

It sounds like it may be worth downloading your records in batches if it's due to take a while. Also, if your database operations are expensive, it's well worth investigating caching your ListItems (there's a CacheVirtualItems event you'll need to handle):

<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.cachevirtualitems.aspx\">http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.cachevirtualitems.aspx

我希望这有助于。

这篇关于我如何填充在虚拟模式下一个ListView异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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