Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridViewImageColumn showing red X on new row

$
0
0

Hello,

When a user adds a row to my DataGridView, my ImageColumn shows a red X instead of the picture I specified.  I've already added a CellPainting handler to blank the cell on the NewRow (below).  How do I handle the same when the user adds the row?

        void grdTests_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (grdTests.Columns["DeleteTest"].Index.Equals(e.ColumnIndex) && e.RowIndex == grdTests.NewRowIndex)
            {

                Rectangle rect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 1, e.CellBounds.Height - 1);

                Bitmap transparentImage = new Bitmap(20, 20);

                e.PaintBackground(rect, true);
                e.Graphics.DrawImage(transparentImage, rect);

                e.Handled = true;

            }
        }

Would it help if I can somehow invalidate or commit the added row?

Regards


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>