How to Add a Binary Stream Image to ListView Columns

In order to add image into ListView's column, you can implement it with the following steps:

1. Add the control ListView named lv and ImageList named imageList from ToolBox into the form.

2. Now assume that there is a binary stream fs:

FileStream fs = new FileStream("D:\\a.jpg", FileMode.Open);

3. Fill image stream into ImageList:

imageList.Images.Add(Image.FromStream(fs));

4. Set the list display mode:

lv.Items.Clear();
lv.LargeImageList = imageList;
lv.View = View.LargeIcon;

5. Add image into the ListView:

lv.BeginUpdate();
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = 0;
lvi.Text = "pic" + 0;
this.lv.Items.Add(lvi);
this.lv.EndUpdate();

6. You can modify the image size by ImageList's Properties.

posted @ 2018-10-23 16:55  Kyle0418  阅读(158)  评论(0编辑  收藏  举报