Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling a ListView with an ImageList using View.Details

Having an issue loading icons in to my listview. I can get the images to work in large view but not in details, not quite sure what I am doing wrong.

private void CreateList()
{
    listView1.View = View.Details;

    listView1.Columns.Add("Icon", -2, HorizontalAlignment.Center);

    listView1.Columns.Add("Name", -2, HorizontalAlignment.Left);

    imageList1.ImageSize = new Size(32, 32);

    for (int i = 0; i < subKeys.Length; i++)
    {
        if (subKeys[i].Contains("App"))
        {
            imagePath = subKeys[i];

            if (System.IO.File.Exists(imagePath))
            {
                imageList1.Images.Add(Image.FromFile(imagePath));
            }

            numberOfImages++;
        }
    }

    listView1.StateImageList = this.imageList1;
}
like image 791
cheeseman Avatar asked Jan 16 '23 21:01

cheeseman


1 Answers

Change

listView1.StateImageList = this.imageList1;

To

listView1.SmallImageList = this.imageList1;

And make sure that you are setting the ImageIndex, or ImageKey properties for each ListItem.

listItem.ImageIndex = 0; // or,
listItem.ImageKey = "myImage";
like image 63
David Anderson Avatar answered Jan 30 '23 22:01

David Anderson