繁体   English   中英

winforms上的虚拟列表视图排序

[英]Virtual list view sorting on winforms

嘿所有,我有一个winforms 虚拟化 Listview,我希望能够排序。 我实现了一个派生自IComparer的分类器类。 现在,每次我想对列表视图进行排序时,我都会执行以下操作:

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
}

我想确定的是 - 这真的是你如何在排序后重置虚拟listview项目? 我是否真的必须将虚拟列表大小设置为0,然后将其重置为新大小?

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

对于winforms的优化(和可排序 )虚拟列表视图,我找不到任何令人满意的代码。

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

_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 ... :)

编辑:排序后调用Refresh()也应该有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM