views:

274

answers:

3

In my project, I have a list box. When I click an item on the listbox, I want the PNG image from a file (stored in Global Varible, GV.dir) into the Picture Box named picBox... this is what I have...

picBox.Image = Image.FromFile(GV.dir + lstFull.SelectedIndex.ToString() + ".png");

GV.dir is equal to -> @"C:\Files"

A: 

You're missing a \ after "C:Files", and are your png's really named 0,1,2,3...etc. Using the .SelectedIndex property will just return the index number (as a string with the .ToString). I think you may want to use SelectedItem.ToString instead.

Stewbob
A: 

You probably need to change this to:

var imageFile = System.IO.Path.Combine(GV.dir, lstFull.SelectedItem.ToString() + ".png");
picBox.Image = Image.FromFile(imageFile);

Note the use of Path.Combine and SelectedItem. The first takes care of missing \ characters in your path. The second will change your text from a number (index) to the text of the item.

Reed Copsey
A: 

thanks Stewbob, I had the \, just forgot to put it in my question, but the SelectedItem.ToString part fixed it...

ArcanaForce0