C#:你是如何做到这一点的,你可以决定你想要哪些项目专门绘制到虚拟模式的列表视图?

时间:2022-08-25 22:01:03

Exact duplicate of How would you only draw certain ListView Items while in Virtual Mode? from same name, different account.

完全重复如何在虚拟模式下只绘制某些ListView项?来自同一个名字,不同的帐户。

@Jonathan: please enhance your question instead of entering a new copy.

@Jonathan:请改进您的问题,而不是输入新的副本。


I am trying to implement a filter mechanism into a listview object (in virtual mode). I have gotten advice to not return the items in question in the retrieve_item event that I do not want displayed, but when I do not return anything less than a listview item (cached from an array of listviewitems holding all my listview items in question) I get an exception error saying that I must return a valid ListViewItem in the RetrieveVirtualItem event like it reads in the msdn it will do.

我试图在listview对象中实现过滤机制(在虚拟模式下)。我已经得到建议,不要在我不想显示的retrieve_item事件中返回有问题的项目,但是当我不返回任何少于listview项目的项目时(缓存来自listviewitems的数组,其中包含我所有的listview项目)我得到一个异常错误,说我必须在RetrieveVirtualItem事件中返回一个有效的ListViewItem,就像它读取msdn一样。

Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.retrievevirtualitem.aspx

So how can I go upon only deciding like items [0], [5], and [11] to be displayed out of a list of let's say listviewitems[25] when I call out one of my own methods so that it does so?

那么,当我调出一个我自己的方法时,我怎么能继续只决定像[0],[5]和[11]这样的项目列表中显示的列表视图[25]。 ?

After my task is done with what ever I want the filter to be used for, I want to revert all the original items back into the listview, how could I come to implement a feature like this?

在完成我想要使用过滤器的任务之后,我想将所有原始项目还原回listview,我怎样才能实现这样的功能?

  // Initialized with 25 listviewitem & subitems objects later during the programs runtime.
  public ListViewItem[] lviCache;

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

    void UnfilterlvItems()
    { 
        // How would I revert it back so that it draws all original items
        // from my listviewitem[] array back to normal to display
        // all 25 objects again?
    }

    void FilterlvItems()
    { 
        // What would I be putting in here so that I can fire off the
        // retrievevirtualitem events and only decide which items I want
        // display for the time being? {0, 5, 11 }
    }

1 个解决方案

#1


You need to do this:

你需要这样做:

  • Build an array, filteredItems, of the indexes of the items you want to show. This will look like [0, 5, 11] in your example
  • 构建要显示的项目的索引的数组filteredItems。在您的示例中,这看起来像[0,5,11]

  • Tell the control to show 3 items: resultsList.VirtualListSize = filteredItems.Count;
  • 告诉控件显示3个项目:resultsList.VirtualListSize = filteredItems.Count;

  • In RetrieveVirtualItem, return the item from your array:

    在RetrieveVirtualItem中,返回数组中的项:

    return lviCache[filteredItems[ev.ItemIndex]];

#1


You need to do this:

你需要这样做:

  • Build an array, filteredItems, of the indexes of the items you want to show. This will look like [0, 5, 11] in your example
  • 构建要显示的项目的索引的数组filteredItems。在您的示例中,这看起来像[0,5,11]

  • Tell the control to show 3 items: resultsList.VirtualListSize = filteredItems.Count;
  • 告诉控件显示3个项目:resultsList.VirtualListSize = filteredItems.Count;

  • In RetrieveVirtualItem, return the item from your array:

    在RetrieveVirtualItem中,返回数组中的项:

    return lviCache[filteredItems[ev.ItemIndex]];