Hi All,
I am Working in C#.Net Technology (Window Based Application).My Problem is that ,I Want to display a Image in DataGridView cell.Iam able to display different Images In different cell of particular Column,But my problem is that Iam getting the image of a Exact Size.What I wan is to Scale a Image so that Whole Iamge is Visible In a Small Size not a Part Of it.
Can any body guide me .

Rahul Joshi

Dani AI

Generated

described the classic symptom: the image is larger than the cell so only a portion is visible. Replies from and pointed in the right direction — the DataGridView image column can scale images rather than draw them at native size. The image column supports three layouts (Normal, Stretch, Zoom); Zoom preserves aspect ratio while fitting the image inside the cell. (learn.microsoft.com)

Concrete, minimal steps (C#):

// set the column layout once (designer or runtime)
var imgCol = (DataGridViewImageColumn)dataGridView1.Columns["ImageColumn"];
imgCol.ImageLayout = DataGridViewImageCellLayout.Zoom;

// size the grid to the target thumbnail size
dataGridView1.RowTemplate.Height = 60;
dataGridView1.Columns["ImageColumn"].Width = 80;

// assign actual Image objects (not raw byte[]), e.g.:
dataGridView1.Rows[rowIndex].Cells["ImageColumn"].Value = Image.FromFile(path);

Setting the column ImageLayout updates every cell in that column; you can override an individual cell after the column is set by casting to DataGridViewImageCell and changing its ImageLayout. Also consider adjusting RowTemplate.Height/column width so the scaled image looks good. (learn.microsoft.com)

Troubleshooting notes: if the grid is data-bound or images come from a database as byte[], convert the bytes to an Image (MemoryStream + Image.FromStream) or detect the cell ValueType in CellPainting/CellFormatting and set the cell's ImageLayout there — bound grids sometimes require runtime adjustments. (stackoverflow.com)

If you need exact pixel thumbnails (no layout mode), create a resized Bitmap and assign that to the cell (Graphics.DrawImage to a new Bitmap) before putting it into the grid — that avoids distortion or unexpected DPI behavior when you want fixed icons. (stackoverflow.com)

Summary: prefer ImageLayout = Zoom for automatic, aspect‑preserving scaling; set row/column sizes to the desired thumbnail dimensions; convert byte[] to Image when binding, and pre-scale if you need precise control.

Recommended Answers

All 6 Replies

What are you using to view the image? If it is a PictureViewer object then just set the sizeMode property of the image to Zoom. Then resize the PictureViewer to whaterver size you want. I'm not sure what your using to view the image though. Is it an excel spreadsheet? Access?

Member Avatar for Member #46692

What are you using to view the image? If it is a PictureViewer object then just set the sizeMode property of the image to Zoom. Then resize the PictureViewer to whaterver size you want. I'm not sure what your using to view the image though. Is it an excel spreadsheet? Access?

I think he wants his image to auto-scale to fit his column in his window application.

What are you using to view the image? If it is a PictureViewer object then just set the sizeMode property of the image to Zoom. Then resize the PictureViewer to whaterver size you want. I'm not sure what your using to view the image though. Is it an excel spreadsheet? Access?

Hi GodFear,

Firstly thanks for replying.
Dear iam using DatagridViewImageColumn to show a Image in a cell.
Problem is it is not showing full image ,it s just showing the part of it image.What i want to show full Image.

Waiting for ur Reply.

Rahul Joshi

Hi All,
I am Working in C#.Net Technology (Window Based Application).My Problem is that ,I Want to display a Image in DataGridView cell.Iam able to display different Images In different cell of particular Column,But my problem is that Iam getting the image of a Exact Size.What I wan is to Scale a Image so that Whole Iamge is Visible In a Small Size not a Part Of it.
Can any body guide me .

Rahul Joshi

Mr . Rahul i hope u solve the problem. i also have the similar problem. plz tell me how can you handle this problem. i am waiting for your reply.

I am working on vb.net,I Want to display a Image in DataGridView cell.Iam unable to display different Images In different cell of particular Column can any body guide me

select stretch property in DatagridViewImageColumn

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.