Hello Developers!
I want to resize images in a DataGridView to fit them properly in the cells but I can’t find the CellPainting Event we use in WinForms.
Please, I need some help on this issue. Below is the code I use in WinForms.
Thank you
Okay. Thank for your support. Since I don’t create DataGridView Columns at Design time, I couldn’t see the UserPaint Property quickly. But I’ve seen it and set it at the FormLoad Event like this;
DataGridView1.Columns(“CustomerImage”).UserPaint = True
And I’ve set the CellPaint Event as below;
Private Sub DataGridView1_CellPaint(sender As Object, e As DataGridViewCellPaintEventArgs) Handles DataGridView1.CellPaint
If (e.RowIndex < 0 Or e.ColumnIndex < 0) Then Return
If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).ValueType = GetType(Byte()) Then
CType(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex),
DataGridViewImageCell).ImageLayout = DataGridViewImageCellLayout.Zoom
End If
End Sub
They seem to work as expected.
Thank you
Hi Ngabo,
The event you’re looking for is CellPaint, make sure to visit our documentation for additional help with the DataGridView!
You have to set the UserPaint property to true for it to work.
HTH,
Alaa
Please login first to submit.