如何在ListView中使用虚拟模式? [英] How to use Virtual mode in ListView?

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

问题描述

我正在使用VirtualMode填充

List<ListViewItem> m_lstItem;


    private void Form1_Load(object sender, EventArgs e)
    {
        m_lstItem = Enumerable.Range(0, 100000).Select(X => new ListViewItem(new String[] { X.ToString(), (X + 1).ToString() })).ToList();
        listView1.VirtualListSize = m_lstItem.Count;
    }

    private void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
    {
        e.Item = m_lstItem[e.ItemIndex];
    }

但是我无法访问所选的项目.访问所选项目时,抛出诸如Cannot access the selected items collection when the ListView is in virtual mode.

but i can not access the selected item. while accessing the selected item its throwing an error like Cannot access the selected items collection when the ListView is in virtual mode.

listView位于VirtualMode

请帮助我做到这一点.

推荐答案

从MSDN:

在虚拟模式下,Items集合被禁用.尝试访问它会导致InvalidOperationException. CheckedItems集合和SelectedItems集合也是如此.如果要检索选定或选中的项目,请改用SelectedIndices和CheckedIndices集合.

In virtual mode, the Items collection is disabled. Attempting to access it results in an InvalidOperationException. The same is true of the CheckedItems collection and the SelectedItems collection. If you want to retrieve the selected or checked items, use the SelectedIndices and CheckedIndices collections instead.

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

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