Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
hi!
i have problem about export picture from picturebox to listbox, i want to use add button to export the picture from picturebox to listbox...
Posted
Updated 11-Feb-14 5:26am
v2
Comments
johannesnestler 11-Feb-14 10:09am    
yes, and what's your Problem? I think with export you mean some kind of selection interface for the user (click through serveral pictures) wich allows to create a list of pictures (represented by your listview), correct? Sounds quite simple, hard to tell where you are stuck...
Renz Pelias 11-Feb-14 10:15am    
sir we use webcam to capture image then after the image was capture it will put in picturebox after that theres a button to put the picture from picturebox to listview
johannesnestler 11-Feb-14 10:24am    
ah ok, I see. So you managed to show the pictures and problem is only how to add the picture to the listview?
Renz Pelias 11-Feb-14 10:26am    
yes sir thats my problem i how i gonna add the picture from picturebox to listview...
johannesnestler 11-Feb-14 10:28am    
wait a Moment - I create an example

You will be able to find enough of code on CodeProject: http://www.codeproject.com/search.aspx?q=Web+camera+capture+Forms&doctypeid=1[^].

—SA
 
Share this answer
 
Hi Renz Pelias,

Here is a runnable example - please replace the picture path (D:\sample.jpg) to a valid path for your system:

C#
using System;
using System.Drawing;
using System.Windows.Forms;

namespace AddPictureToListView
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Form form = new Form();

            PictureBox pb = new PictureBox { Dock = DockStyle.Top, Image = Bitmap.FromFile(@"D:\sample.jpg") };
            ListView lv = new ListView { Dock = DockStyle.Fill };
            lv.LargeImageList = new ImageList();

            Button button = new Button { Text = "Add", Dock = DockStyle.Top};

            button.Click += (object sender, EventArgs e) =>
                {
                    string strKey = "Image" + lv.LargeImageList.Images.Count; 
                    lv.LargeImageList.Images.Add(strKey, pb.Image);

                    ListViewItem item = new ListViewItem("Text representing image", strKey);
                    item.Tag = pb.Image;   
                    
                    lv.Items.Add(item);
                };

            form.Controls.Add(lv);
            form.Controls.Add(button);
            form.Controls.Add(pb);

            Application.Run(form);
        }
    }
}


So the trick is to fill the image list(s) and wire up the listview items to it. I also added the original Image as Tag to the ListViewItem (maybe nice if you later want to do something with the original). There are two ways to wire the Images up, with keys - the approach I used in the example or just by index (more usefull for static Image list).

But I have to say that maybe a ListView is not ideal for your usecase. You can also use a Panel (Wrap,Panel) and just add PictureBoxes (or owner-draw it for better Performance) to it. (Don't forget to turn Scrolling on...)

If you have any further questions, feel free to ask - happy coding

Kind regards
Johannes
 
Share this answer
 
Comments
Renz Pelias 11-Feb-14 10:57am    
sir i want to ask if you have an idea regarding capturing an image and put it in picture box transfer it into listview whenever a is button click...
johannesnestler 11-Feb-14 13:28pm    
That is what this example shows - you have a picturebox a button and a listview. I don't think your solution is in general a good aproach (listen to SA) - but all you need is in the example I think. What was your problem - the ImageList thing?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900