Already changed it.
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataGridViewComboBoxCell Shape = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells[10];
if (e.ColumnIndex == Shape.ColumnIndex)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
try
{
using (SqlCommand cmmd = new SqlCommand("SELECT shapeImage FROM shapeTable WHERE shapeCode = @shapeCode", conn))
{
try
{
cmmd.Parameters.AddWithValue("@shapeCode", Shape.Value);
conn.Open();
byte[] bytes = (byte[])cmmd.ExecuteScalar();
conn.Close();
Image img = byteArrayToImage(bytes);
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
row.Cells[11].Value = img;
}
catch (Exception ex)
{
MessageBox.Show("Error\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
dataGridView1.Invalidate();
}
catch (Exception ex)
{
MessageBox.Show("Error\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}