我如何在ListView的起始索引和可见项目的数量? [英] How do I get the start index and number of visible items in a ListView?
问题描述
我有一个ListView在虚拟模式下工作,在LargeIcons视图。检索是昂贵的,所以我想询问所有可见项目的数据。我如何获得可见项目的启动指数和总人数?
I have a listview working in virtual mode, in the LargeIcons view. Retrieves are expensive, so I want to ask for the data for all the visible items. How do I get the start index and total number of the visible items?
更新:我知道了CacheVirtualItems事件。我们使用第三方数据库需要3秒〜检索单个记录,但4S〜检索上千条记录,所以我必须做他们大块。我需要确保在可见的记录是那些我们检索中,所以我需要知道可见项目的启动指数和总数量。如果这不可行,我必须找到一个解决方法(这可能会涉及使用一个DataGridView与图像细胞负载模仿LargeIcons视图),但我想正确如果可能做到这一点。
Update: I am aware of the CacheVirtualItems event. The third-party database we're using takes ~3s to retrieve a single record, but ~4s to retrieve a thousand records, so I have to do them in large blocks. I need to make sure the visible records are among those we retrieve, so I need to know the start index and total number of the visible items. If that's not feasible, I'll have to find a workaround (which will probably involve using a DataGridView with a load of image cells to imitate the LargeIcons view) but I would like to do this properly if possible.
推荐答案
刚刚送走我的头顶,我没有测试过这一点,但你可以这样做:
Just off the top of my head, and I haven't tested this but could you do:
private void GetIndexes(ListView vv, out int startidx, out int count)
{
ListViewItem lvi1 = vv.GetItemAt(vv.ClientRectangle.X+6, vv.ClientRectangle.Y + 6);
ListViewItem lvi2 = vv.GetItemAt(vv.ClientRectangle.X+6, vv.ClientRectangle.Bottom-10);
startidx = vv.Items.IndexOf(lvi1);
int endidx = vv.Items.IndexOf(lvi2);
if (endidx == -1) endidx = vv.Items.Count;
count = endidx - startidx;
}
这篇关于我如何在ListView的起始索引和可见项目的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!