虚拟列表视图上的WinForms排序 [英] Virtual list view sorting on winforms

查看:234
本文介绍了虚拟列表视图上的WinForms排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,
我有一个WinForms 虚拟化列表视图,我希望能够进行排序。
我实现了从的IComparer 派生的分拣机类。
现在,每次我想我的排序列表视图我做到以下几点:

Hey all, I have a winforms virtualized Listview that i want to be able to sort . I implemented a sorter class that derives from IComparer . Now, every time i want to sort my listview i do the following :

public void SortMyVirtualListView()
{
    this.VirtualListSize =  0; // set virtual size to 0
    _myInnerList.Sort(_myComparer); // sort the inner listlistview items source)
    this.VirtualListSize = _myInnerList.Count; // re-set the virtual size to items count
}

我要确保是什么 - 这真的是你如何排序后重新设置虚拟列表视图的项目?难道我真的对虚拟列表大小设置为0,然后将其重新设置为新的大小?

What i want to make sure is - Is this really how you reset the virtual listview items after a sort? Do I really have to set the virtual list size to 0 and then reset it to the new size ?

好像我不能省略有关VirtualListSize设置为零,然后在重新排序的基础列表部分,设置VirtualListSize回到其原始值( this.VirtualListSize = _myInnerList.Count )。

It seems like i cannot omit the part about setting the VirtualListSize to zero and then,after re-sorting the underlying list, set the VirtualListSize back to its original value (this.VirtualListSize = _myInnerList.Count).

我找不到任何一种令人满意的code,为优化(和排序)进行的WinForms虚拟列表视图。

I could not find any kind of a satisfying code for an optimized (and sortable) virtual list view for winforms .

推荐答案

是否与设置VirtualListSize一些性能问题?这是有道理的,因为ListView控件不知道你的内部列表已经改变,所以你需要以某种方式告诉它。
如果以这种方式重新VirtualListSize导致性能问题,也许只是重新绘制可见的项目有差别?

Is there some performance problem with setting VirtualListSize? This makes sense, because ListView has no idea that your inner list has changed, so you need to tell it somehow. If resetting VirtualListSize in this manner is causing performance problems, maybe just redrawing the visible items makes a difference?

_myInnerList.Sort(_myComparer); // sort the inner listlistview items source)
int startIndex = this.TopItem == null ? 0 : this.TopItem.Index;
int endIndex = Math.Min(startIndex + 100, this.VirtualListSize - 1);
this.RedrawItems(startIndex, endIndex, true);

(是的,我知道,我不喜欢的幻数100要么...:)

(Yes, I know, I don't like the magic number 100 either... :)

编辑:排序应太后调用refresh()

Calling Refresh() after sorting should work too.

这篇关于虚拟列表视图上的WinForms排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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