Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert items in listView to files?

files in listview1

how i’m adding the files to the listview in constructor

listView1.View = View.List;
            string[] files = Directory.GetFiles(@"d:\New folder (4)");
            for (int i = 0; i < files.Length; i++)
            {
                listView1.Items.Add(files[i]);
            }

for example the first file in the listview is d:\New folder (4)\myimage.jpg
when running the application i want to display the file in picturebox1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i tried this in the constructor

img1 = Image.FromFile(listView1.Items[0].ToString());

but getting error on that line

System.NotSupportedException: ‘The given path’s format is not supported.’

>Solution :

You must read the text of an item. Items[0] returns an object. You must read the Items[0].Text: so edit this line:

//img1 = Image.FromFile(listView1.Items[0].ToString());
img1 = Image.FromFile(listView1.Items[0].Text);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading