简体   繁体   中英

DataGridView ImageColumn Displays PNG Picture withTransparent Background keeping previous Drawing in Picture location Winform VB.NET

I'm using ImageColumn in datagridview to view PNG Pictures saved in DB. Whenever I change tabs in my Form and go back to the Tab with DGV the PNG imgae transparent background keeps the drawing of the previous Control that was displayed in the same location. Also When I tried to change the Image and save a New PNG image the DGV is updated and it displays parts of the previous picture in the transparent part. I change Background color and SelectionBackground color in the imageColumn cell default style options to WHITE but nothing is changed. Can any body help me to solve this issue? Please see pictures for clearance.. 在此输入图像描述

Finally Solved by code!

Used CellPaining to draw a white rectangle in the cell.

Private Sub ItemsList_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles ItemsList.CellPainting
        If ItemsList.Columns(e.ColumnIndex).Name = "iconCol" And e.RowIndex >= 0 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All)
            e.Graphics.FillRectangle(Brushes.White, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Width, e.CellBounds.Height)
        End If

Don't use DrawRectangle use FillRecangle to draw the rectangle so the background is filled with the color.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM