简体   繁体   中英

How to add an image to ListViewItem or ListView c#

I have a listview control, to this control I am adding rows which contain image data, filename, position (its taken at a point in a 4 dimensional matrix), time taken. To make things nice I want to add a 'delete' icon to my fourth column so the user can review the image and decide whether to keep it or not, how do I add an image/icon to that 4th cell in each row?

public void addItemToImageListview(string details, string timestamp)
{
        string reftype = (!exp_image_radiobtn.Checked) ? "Ref" : "Data";
        ListViewItem lvi = new ListViewItem();

        if (details.Contains("[ERROR]"))
        {
            reftype = "[ERROR]";
            details = details.Substring(0, details.IndexOf("[ERROR]"));
        }

        lvi.Text = details;
        lvi.SubItems.Add(reftype);
        lvi.SubItems.Add(timestamp);
        lvi.SubItems.Add(image icon?);

I have looked through Google but a lot of stuff is old...

As Aren asked, this is a winforms app, c#, 3.5.

Unfortunately, in WinForms rendering a column as an image gets painful. You have to create an owner-drawn ListView and provide the logic for drawing that column.

Fortunately, there's the open source ObjectListView wrapper , which makes drawing images in ListView subitem columns trivial:

替代文字

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM