c# - 如何在 ListView 中使用虚拟模式?

标签 c# winforms 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];
    }

但我无法访问所选项目。在访问所选项目时抛出错误,如 当 ListView 处于虚拟模式时无法访问所选项目集合。

listView 处于 VirtualMode 时如何获取选中的项目

请帮我做这件事。

最佳答案

来自 MSDN:

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.

关于c# - 如何在 ListView 中使用虚拟模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5415877/

相关文章:

android - 使水平 ListView 的列表项的高度动态

c# - Visual Form 继承不适用于 Visual Studio 2008 中的智能设备/紧凑型框架

c# - 在C#的 “getTickFrequency”中相当于来自OpenCV的 “Emgu”?

c# - 在 C# 的 ListView 中删除相同的数字

c# - 保持一个拆分容器面板固定宽度?

c# - 网络客户端 : Download Not Complete: The remote server returned an error: (403) Forbidden.

android - ListView 工具 :listitem not working in android studio 2. 2 稳定 channel

c# - 不使用 C# 命名空间有什么危险?

c# - WebChannelFactory 和标题?

c# - 无边框形式的 Windows 7 风格 Dropshadow