4

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

Võ Quang Hòa
  • 2,688
  • 3
  • 27
  • 31

1 Answers1

8

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.

alex
  • 3,710
  • 32
  • 44
  • 1
    Thanks you. I have just tested and result is successfull. – Võ Quang Hòa Apr 19 '11 at 07:30
  • 1
    @VõQuangHòa: Glad I could help. If this solved your problem, please mark the answer as accepted. – alex Apr 19 '11 at 08:45
  • I have just read this rule from faq. But I'm sorry, I can't see "accepted answer" any where. Please help me. Thanks you – Võ Quang Hòa Apr 19 '11 at 15:06
  • 1
    Source link is now dead (good job Microsoft, sigh) so whatever background information it contained is lost but the answer of using `ImageIndex` over `ImageKey` is still valid 6 years on having just been bitten by the exact same issue. – Richard Moss Mar 10 '18 at 13:03
  • @RichardMoss Just like the classic **_This thread has been closed as of 26/Oct/2009_** – Sreenikethan I Jan 30 '19 at 16:24