【问题标题】:Make sure ListViewItem is shown in a ListView确保 ListViewItem 显示在 ListView 中
【发布时间】:2011-11-02 12:29:12
【问题描述】:

我有一个很长的 ListView,其中包含我的应用当前正在运行的操作列表(一次每个操作)。 在运行每个操作时,相关的 ListViewItem 会以粗体显示。 ListView 很长,所以我有垂直滚动条。

我的问题是如何向用户显示当前正在运行的操作,这意味着我如何将列表视图“滚动”到该项目。

我尝试手动选择行 ==> 不起作用。 我使用了 ListViewItem.EnsureVisible 但这使得 ListView 在每次更改时都会闪烁。

有什么想法吗?谢谢。

已编辑:我添加了一些代码,尽管代码非常简单。 每当运行新操作时,我都会运行以下命令:

foreach (ListViewItem item in m_ListView.Items)
{
    FontStyle style = ((index == value) ? FontStyle.Bold : FontStyle.Regular);
    item.Font = new Font(item.Font, style);

    if (index == value)
    {                        
         m_ModulesListView.EnsureVisible(index);
    }

    index++;
}

【问题讨论】:

  • 嗨,请显示一些代码,尤其是您调用 EnsureVisible 的方式...这应该是首选解决方案,关于闪烁它可能取决于您调用它的方式以及您对控件的操作。

标签: c# winforms listview


【解决方案1】:

你的意思

listView1.EnsureVisible(listView1.Items.Count - 1);

【讨论】:

  • 我的意思是 ListViewItem.EnsureVisible 与 ListView.EnsureVisible 的作用相同(我不是指静态函数,如果你这么想的话)......当然它在 ListViewItem 实例上。无论如何,在 ListView 上执行相同的操作会得到相同的结果...... ListView 在每次更改时都会闪烁。
【解决方案2】:

也许您应该在循环之前调用ListView.BeginUpdate(),在循环之后调用ListView.EndUpdate()

【讨论】:

    【解决方案3】:

    找到了一个不错的solution。 它涉及使用win32,但它可以完成这项工作。 显然,可以在列表上设置双缓冲来解决闪烁问题。 所以,使用 EnsureVisible 和双缓冲就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 2013-12-30
      相关资源
      最近更新 更多