.NET:ListView 的 TopItem 属性因“ShowGroups"而失败;= 真 [英] .NET: TopItem property of ListView fails with "ShowGroups" = true

查看:24
本文介绍了.NET:ListView 的 TopItem 属性因“ShowGroups"而失败;= 真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示大约 300 个项目的 ListView.当某些内容发生更改并且我需要重新填充列表时,我希望滚动位置保持不变,因此相同的项目仍然可见并且位于列表中的相同位置.EnsureVisible"方法很烂,因为它满足Visible",而不是相同的位置(结果是感兴趣的项目总是滚动到列表底部).

I have a ListView that shows around 300 items. When something is changed and I need to repopulate the list, I would like the scroll position to be unchanged, so the same items are still visible and in the same position in the list. The "EnsureVisible" method sucks since it is satisified with "Visible", not the same position (the result is that the item of interest is always scrolled to the bottom of the list).

我的解决方法是保存List->TopItem的(我的)ID",重新填充列表然后调用List->TopItem = newItemWithSameID(需要设置两次才能工作).这对基本的未分组"列表很有用.

My solution to the problem is to to save the (my) "ID" of the List->TopItem, refill the list and then call List->TopItem = newItemWithSameID (needs to be set twice to work for some reason). This works as a charm for basic "ungrouped" lists.

但是 - 如果列表有ShowGroups = true",这将不起作用.属性 TopItem 将始终是列表中的第一项,而不是文档所说的第一个 VISIBLE 项.

BUT - if the List has "ShowGroups = true" this will not work. The property TopItem will then always be the first item in the list, not the first VISIBLE item as the documenation says.

有解决办法吗?我用谷歌搜索,发现另一个迷失的灵魂也有同样的问题.他对 Microsoft 的支持进行了相当有趣的讨论,但没有成功.(http://social.msdn.microsoft.com/Forums/en/winforms/thread/8a81c5a6-251c-4bf9-91c5-a937b5cfe9f3).

Is there a solution? I googled around and found another lost soul having the same problem. He had a rather funny discussion on Microsoft support about it, without success.(http://social.msdn.microsoft.com/Forums/en/winforms/thread/8a81c5a6-251c-4bf9-91c5-a937b5cfe9f3).

所以 - 我的问题是:有解决方法吗?我真的需要对列表进行分组,而且我真的很讨厌当某些内容发生变化时列表会跳来跳去.

So - my question is: is there a workaround? I really need the list to be grouped, and I really hates when the list jumps around when something is changed.

我不会在这里粘贴任何代码,因为您需要复制的所有代码都在上面的讨论中.

I won't paste any code here, since all the code you need to reproduce this is in the discussion above.

非常感谢!

推荐答案

这是我用于解决此问题的解决方法:

Here's a workaround that I have used for this problem:

public ListViewItem RealTopItem
{
    int i = 0;
    while (i < Items.Count && !ClientRectangle.Contains(Items[i].Bounds))
        i++;

    return Items[i];
}

不幸的是,最近在我的代码中工作了一年后,客户在 while 语句中失败了.在我的故障排除中,我首先尝试停用组,问题就消失了.然后当我再次重新激活组时,问题再也没有发生.我现在不知道那里有什么问题.

Unfortunately, it just recently failed for a customer in the while-statement after having worked for a year in my code. In my troubleshooting, I first tried to deactivate groups, and the problem went away. Then as I reactivated groups again, the problem never reoccured. I have no idea right now what could be wrong there.

这篇关于.NET:ListView 的 TopItem 属性因“ShowGroups"而失败;= 真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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