【问题标题】:Listview virtualmode not able to add items dynamicallyListview 虚拟模式无法动态添加项目
【发布时间】:2014-10-17 12:49:48
【问题描述】:

所以我一直在虚拟模式下使用ListView,但我似乎无法动态添加项目。我想从List 加载项目并将它们显示在我的ListView 中。这是我到目前为止的代码。

private void listviewGames_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
    if (listGames[1].Count < 1) return;

    for (int index = 0; index < listGames[1].Count; index++)
    {
        ListViewItem lvi = new ListViewItem();

        lvi.Text = listGames[1][index];

        e.Item = lvi;
    }
}

可悲的是,这段代码似乎不起作用,它只添加了List 中的最后一项,这是为什么呢?
提前致谢,

蓝宝石~

【问题讨论】:

  • 您是否设置了 VirtualListSize 属性?
  • @terrybozzio 是的,我在 form_Load 事件中做到了。

标签: c# winforms list listview


【解决方案1】:

请试试这个:

private void listviewGames_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
    if (listGames[1].Count < 1) return;


    ListViewItem lvi = new ListViewItem();

    lvi.Text = listGames[1][e.ItemIndex];

    e.Item = lvi;

}

【讨论】:

  • 成功了!今天学到了一些新东西:)。谢谢^-^~!
  • 你最开心了:)
猜你喜欢
  • 1970-01-01
  • 2011-04-23
  • 1970-01-01
  • 2012-09-04
  • 2012-08-27
  • 2016-05-13
  • 1970-01-01
  • 2021-04-11
  • 2015-12-18
相关资源
最近更新 更多