423,321 Members | 1,167 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,321 IT Pros & Developers. It's quick & easy.

TableLayout panel and picturebox in window form application

P: 3
Hello tell me how to add picture box in runtime using c# me attach pic and me doing pic path add in database and still error you can see picture and plz tell me its urgent

Attached Images
File Type: jpg 1.jpg (32.8 KB, 251 views)
Dec 4 '17 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
That error states that there is no imagepath column in your table.

Double check that you Have a column that holds your image path.

Double check your column name that holds the image path.
Dec 5 '17 #2

Frinavale
Expert Mod 5K+
P: 9,731
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:

Expand|Select|Wrap|Line Numbers
  1. String imagePath = @"C:\TestPicture\testImage.png";
  2. picture.ImageLocation = imagePath;

I tested this code (because I'm not very familiar with the PictureBox control) and it works fine:
Expand|Select|Wrap|Line Numbers
  1. public Form1()
  2. {
  3.   InitializeComponent();
  4. }
  5.  
  6. private void Form1_Load(object sender, EventArgs e)
  7. {
  8.   PictureBox picture = new PictureBox
  9.   {
  10.     Name = "pictureBox",
  11.     Size = new Size(316, 316),
  12.     Location = new Point(5, 5),
  13.     BorderStyle = BorderStyle.FixedSingle,
  14.     SizeMode = PictureBoxSizeMode.Zoom
  15.   };
  16.   picture.ImageLocation = @"C:\testPicture\testImage.png";
  17.   this.Controls.Add(picture);
  18.   this.Size = new Size(416, 416);
  19. }
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.
Dec 6 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.