简体   繁体   English

如何在虚拟模式下显示所有列表视图项目上的图标(C#)

[英]How to show icon on all listview items in virtual mode (C#)

I'm using virtual mode of listview to show a larg data. 我正在使用listview的虚拟模式来显示大数据。 But I don't know how to show image for each item. 但我不知道如何显示每个项目的图像。 Who can help me ? 谁能帮我 ?

I wrote 我写

private void ListContact_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
    {
        MyContact contact = ContactData.GetMyContact(e.ItemIndex);
        if (e.Item == null) e.Item = new ListViewItem(contact.ToString());
        if (contact.Photo != null)
        {
            e.Item.ImageList.Images.Add("" + contact.Id, contact.Photo);
            e.Item.ImageKey = "" + contact.Id;
        }
        else
        {
            e.Item.ImageKey = "default";
        }
    }

But it don't work properly 但它不能正常工作

This seems to be a bug in the .NET Framework (that's been marked as Won't fix ). 这似乎是.NET Framework中的一个错误(已被标记为无法修复 )。 You might want to check this out. 你可能想看看这个 The solution would be to use ImageIndex instead of ImageKey . 解决方案是使用ImageIndex而不是ImageKey

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

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