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
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);
