Datagridview selected record to show in picturebox
-
Wednesday, February 23, 2011 7:12 PM
When pressing a button I select some records from a datagridview I would now like to have the picture shown in pictures boxes from a certain cell, and I am trying to create a byte, but I am not succeeding. Hopefully you can help I am kind of lost.
string playerImg = string.Format("{0}", dgCompetingPlayers.Rows[i].Cells[1].Value); I would like to convert this to byte, but how??
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(playerImg);
MemoryStream ms = new MemoryStream(bytes.ToArray());
Image image = Image.FromStream(ms); Here the ERROR Parameter is not valid.....
pictureBox1.Image = image;
All Replies
-
Wednesday, February 23, 2011 8:44 PM
What does the string "playerImg" look like before it's converted to bytes? What does it have in it?
Jim
-
Thursday, February 24, 2011 3:01 PMModerator
Hi Scorgi,
Thank you for posting.
Based on your description, would you want to click a button and raise an event to assign an image was in the datagridview to a PictureBox control? If I misunderstood, please feel free to let me know.
Well, I think I need to share some ideas and code snippets with you. Just my option, but it works well on my side. First of all, I used DataGridView’s CellClick event to achieve this task. Then, I used Image.GetThumbnailImage method. Here’s my sample. Please check it.private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int a = e.ColumnIndex; int b = e.RowIndex; Image.GetThumbnailImageAbort myImage = new Image.GetThumbnailImageAbort(ThumbnailCallback); Image image1 = ((Image)this.dataGridView1.Rows[b].Cells[a].Value).GetThumbnailImage(200, 200, myImage, IntPtr.Zero); this.pictureBox1.Image = image1; } public bool ThumbnailCallback() { return false; }
Sincerely,
Larcolais
Larcolais Gong[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Marked As Answer by Larcolais GongModerator Sunday, March 06, 2011 2:25 PM
-
Thursday, March 03, 2011 3:05 PMModerator
Any update? Has your question been resolved?
Best Regards,
Larcolais Gong[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


