Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
835 views
in Technique[技术] by (71.8m points)

winforms - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

alt text


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...