Question : How to add pictures to a listview control.

I'm adding the path to the video files to the listview control but i cant figure out how to add an image to each row or item.  here is the code i'm using:

listView1.Items.Clear();
                foreach (string files in Directory.GetFiles(dlg.SelectedPath))
                {
                    if ((files.EndsWith(".avi")) || files.EndsWith(".mpeg"))
                    {
                        listView1.Items.Add(files);
                    }
                }
How can i add an image and only list the name of the file not the whole path?

Any help would be appreciated.

Thanks

Answer : How to add pictures to a listview control.

OR if you really really want the video image icon? Here it is;
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
        private void button6_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.ShowDialog(); 
            if (dlg.SelectedPath == "") return;
            foreach (string files in Directory.GetFiles(dlg.SelectedPath))
            {
                if ((files.EndsWith(".avi")) || files.EndsWith(".mpeg"))
                {
                    ImageList Imagelist1 = new ImageList();
                    Imagelist1.ColorDepth = ColorDepth.Depth32Bit; 
                    Imagelist1.ImageSize = new Size  (100, 80);
                    listView1.View = View.LargeIcon;
                    listView1.LargeImageList = Imagelist1;
                    ListViewItem ThumbEntry = new ListViewItem();
                    ThumbEntry.Text = files;

                    Icon eIcon = System.Drawing.Icon.ExtractAssociatedIcon(files);
                    Imagelist1.Images.Add(eIcon);

                    ThumbEntry.ImageIndex = Imagelist1.Images.Count - 1;
                    listView1.Items.Add(ThumbEntry);
                }
            }
        }
Random Solutions  
 
programming4us programming4us