Search code examples
c#winformslistviewitem

C# WinForms - ListViewItem image not showing


I have a rather trivial problem with image not showing up for each ListViewItem. There should be an image next to each service name, but none shows up. Application.EnableVisualStyles(); is turned on. I tried setting resource images to PictureBox as a test and that works ok. Both column headers were added in designer. Indexes get correctly set for each item, also tried with assigning ImageKey.

Already read multiple similar questions on here, but none solve this problem.

Initialization of ImageList done on load

    ImageList serviceLogoList = new ImageList
    {
        ImageSize = new Size(32, 32),
        ColorDepth = ColorDepth.Depth32Bit
    };

    serviceLogoList.Images.Add(Properties.Resources.drive_logo);
    serviceLogoList.Images.Add(Properties.Resources.dropbox_logo);
    serviceLogoList.Images.Add(Properties.Resources.seeyou_logo);

    listViewDisablableItemsServices.View = View.Details;
    listViewDisablableItemsServices.LargeImageList = serviceLogoList;
    listViewDisablableItemsServices.SmallImageList = serviceLogoList;

Assigning the images to each row

foreach (var service in _services)
{
    if (service.ServiceType == Constants.SERVICE_TYPE_STORAGE)
    {
        ListViewItem item = new ListViewItem(service.Label);
        item.SubItems.Add(service.ErrorOrInterpretedError ?? Lang.GetString("Common_OK"));
        item.Tag = service;

        switch (service.ServiceName)
        {
            case "google":
                item.ImageIndex = 0;
                break;
            case "dropbox":
                item.ImageIndex = 1;
                break;
            case "seeyou":
                item.ImageIndex = 2;
                break;
        }

        listViewDisablableItemsServices.Items.Add(item);

        if (!service.IsAuthenticatedAndAvailable)
        {
            listViewDisablableItemsServices.DisableItem(item);
        }
    }
}

Where images should show up

Location of images


Solution

  • Removing and then re-adding the ListView component in my original code solved the issue. Also the Visual Studio has been restarted after re-adding it.