Sharoo,
I don't have a lot of experience with picture boxes but try this and see if it fixes your problem.
Put your picture, called "testImage.png" into a folder with a known location...like
C:\TestPicture\
.
So the path to the image will be
C:\TestPicture\testImage.png
.
Now, change the line of code that you are having problems with to a string containing this path:
- String imagePath = @"C:\TestPicture\testImage.png";
-
picture.ImageLocation = imagePath;
I tested this code (because I'm not very familiar with the PictureBox control) and it works fine:
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
PictureBox picture = new PictureBox
-
{
-
Name = "pictureBox",
-
Size = new Size(316, 316),
-
Location = new Point(5, 5),
-
BorderStyle = BorderStyle.FixedSingle,
-
SizeMode = PictureBoxSizeMode.Zoom
-
};
-
picture.ImageLocation = @"C:\testPicture\testImage.png";
-
this.Controls.Add(picture);
-
this.Size = new Size(416, 416);
-
}
This picture box works fine with a string that contains the path provided to it's ImageLocation property.
Your problem is that your DataTable does not contain a column named "Imagepath".
You need to make sure your DataTable contains this column and that this column actually contains data.