Reputation: 306
i have a table in my database in which contains an Image_ID, Image, Image_Name and Recipe_ID.
I am trying to edit these in a seperate form. So when a row in the dataGridView is selected it will open up in the edit form with the relevant areas filled out with data.
I am able to do it with all data apart from the Image. Obviously i need to somehow convert it as like i have done with the text fields but i have no idea on how to do so.
Edit Image Row
//Edit image row
private void EditImageBtn_Click(object sender, EventArgs e)
{
try
{
EditImageForm Image = new EditImageForm();
Image.imageidTxt.Text = this.imageGridView.CurrentRow.Cells[0].Value.ToString();
//Image.picImg.Text = this.imageGridView.CurrentRow.Cells[1].Value.ToString();
Image.nameTxt.Text = this.imageGridView.CurrentRow.Cells[2].Value.ToString();
Image.recipeCombo.Text = this.imageGridView.CurrentRow.Cells[3].Value.ToString();
Image.ShowDialog();
loadImageTable();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
Upvotes: 1
Views: 66
Reputation: 341
If your image is stored bytes, you can try something similar to the below to convert the bitmap to an Image type:
byte[] bitmap = this.imageGridView.CurrentRow.Cells[1].Value;
Image image = Image.FromStream(new MemoryStream(bitmap))
More info: https://msdn.microsoft.com/en-us/library/9t4syfhh.aspx
Upvotes: 2