user5373038
user5373038

Reputation:

How to load listview with images from project resources

I am wondering how I can take a image that's in the project settings resources and load this image into a listview without a imagelist. I am getting errors about a imagelist not loading correctly everyone once in a while so I am trying to find a way I can remove the image list without loosing the images I have in the listview.

Upvotes: 0

Views: 2332

Answers (1)

igorc
igorc

Reputation: 2034

This is the what you can do without implementing some custom list:

private void Form1_Load(object sender, EventArgs e)
{
    ImageList imageList = new ImageList {ImageSize = new Size(200, 200)};
    Image img = new Bitmap(Properties.Resources.Your_Image);
    imageList.Images.Add(img);
    this.listView1.View = View.LargeIcon;
    this.listView1.Items.Add(new ListViewItem { ImageIndex = 0 });
    this.listView1.LargeImageList = imageList;
}

If you need more advanced functionality from your listview take a look at this.

Upvotes: 2

Related Questions