How to add image to list in c #?

I have a windows application where data comes in via json. I analyzed the data and was able to show it in a list.

Now I want to add an image in s. I tried a lot of things, but this does not work. According to my need.

Read how I will show this data in the list.

I am using this code.

listView1.Columns.Add("brand", 100, HorizontalAlignment.Left); listView1.Columns.Add("rating", 100, HorizontalAlignment.Left); listView1.Columns.Add("max_price", 100, HorizontalAlignment.Left); listView1.SmallImageList = imageList1; foreach (var item in lstItemDetails) { ListViewItem objListViewItem = new ListViewItem(item.image_medium); objListViewItem.SubItems.Add(item.brand); objListViewItem.SubItems.Add(item.rating); objListViewItem.SubItems.Add(item.max_price); if (!string.IsNullOrEmpty(item.rating)) { int rating = int.Parse(item.rating); objListViewItem.ImageIndex = rating; } else { objListViewItem.ImageIndex = 0; } listView1.Items.Add(objListViewItem); } 

Only the last assigned image is displayed. starting rating image in accordance with item.rating indicator.

Please suggest me the best way to solve this problem.

+4
source share
1 answer

If you do anything with a ListView, you are doing a great service and use ObjectListView instead . ObjectListView is a wrapper around the standard .NET ListView that provides methods for just about anything you might want, plus fixes for almost all the problems / errors that ListView has.

For example, it can create an entire ListView - complete with sorting, grouping, and editing - just by creating columns and then calling SetObjects()

enter image description here

+4
source

All Articles