Hi All,
I have created a windows forms application and using datagridView in one of the forms. I need to add a new Image column dynamically( the image is already availble in the datasource) and just compress it's size and displaying in the new column.
I found that it's always displaying the same image through out all the rows. I need different images in each of the rows.Is it possible? Please find the source code and advice.
DataGridViewImageColumn imgCol = new DataGridViewImageColumn();
{
imgCol.CellTemplate = new DataGridViewImageCell();
imgCol.Width = 100;
imgCol.Name = "imgThumb";
imgCol.HeaderText = "Thumb Image";
}
grdVisitor.Columns.Add(imgCol);
foreach (DataGridViewRow rw in grdVisitor.Rows)
{
byte[] bytImg = (byte[])grdVisitor.Rows[rw.Index].Cells["Image"].Value;
MemoryStream ms = new MemoryStream(bytImg);
Image img = Image.FromStream(ms);
int scaledY = Math.Min(100, img.Height / (img.Width / 100));
int scaledX = Math.Min(100, img.Width / (img.Height / 100));
grdVisitor.Rows[rw.Index].Cells["Image"].Value = img.GetThumbnailImage(scaledX, scaledY, null, System.IntPtr.Zero);
imgCol.Image = img.GetThumbnailImage(scaledX, scaledY, null, System.IntPtr.Zero);
}<br/>
I have written this in the Form_load Event. Kindly let me know how to achieve a different image in each row.
Thanks