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

孤街醉人 提交于 2019-11-28 08:32:46

问题


I'm using virtual mode of listview to show a larg data. 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


回答1:


This seems to be a bug in the .NET Framework (that's been marked as Won't fix). You might want to check this out. The solution would be to use ImageIndex instead of ImageKey.



来源:https://stackoverflow.com/questions/5712164/how-to-show-icon-on-all-listview-items-in-virtual-mode-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!