I have a Datagridview dgv
, let's say with 3 of the columns I want to affect manually are :
col1 : DataGridviewTextboxColumn, for displaying a number
col2 : DataGridviewTextboxColumn, used as a color indicator, without text. BackColor will will be changed later.
col3 : DataGridviewImageColumn
Other columns are binded with their respective DataPropertyName
of the underlying Datasource
. The 3 columns above are not binded to any DataPropertyName
and to be affected manually, for example when I want to change the image or color indicator.
Every time I affect the DataSource
, I do a datasource rebind and dgv.Invalidate()
to update the grid's graphic.
- When and how do I ask the
dgv
to take into account the manual values in 3 edited columns ? Previously I manually affect the 3 above column insidedgv_CellPainting
. It will work but CellPainting takes a long time and we decide to remove it. I tried putting them insidedgv_Paint
(which I used for merging headers) but it does not take the color nor the image.
With CellPainting : rectangles for spaces between rows, filling the background, separater between rows, boxes for image and color, etc. The 3 columns I am refering to are the first column (index), color and image (in boxes) columns. Other image are constant.
Without CellPainting: No row and column separation. I created a pseudo row separation by setting grid's cell border to horizontal.
- When is
CellPainting
andPaint
called? What is the execution order and their difference? My rough understanding is that they are called when the cell/grid "need to be repainted". But I notice they are called multiple times, not just when I callInvalidate()
but even when I hover the mouse over the grid region.
Thanks all.