Link to home
Start Free TrialLog in
Avatar of alan_ITG
alan_ITGFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Datagridview - repainting screen flicker issue

How do I control a DataGridView repainting itself every time I make a change?  I have a couple of procedures that change the backcolor of cells in the DGV according to the cell contents. This causes the DGV to repaint itself causing screen flicker and slowing the code down.  Is it possible to turn the repainting of the control on and off?  If so, how is this accomplished?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

>>couple of procedures that change the backcolor of cells in the DGV according to the cell contents

How are you doing this?

Bob
Avatar of alan_ITG

ASKER


I have a DGV with circa 20 columns set a check boxes. If the checkbox is checked, I want the background to be light green, if unchecked, white.

The code is as follows:

Dim c as datagridviewColumn
Dim r as datagridviewRow
For each c in DGV.columns
For each r in DGV.rows
If r.cells(c.index).value = true then
   dgv.item(c.index,r.index).style.backcolor = color.lightgreen
else
   dgv.item(c.index,r.index).style.backcolor = color.white
end if
next
next
What event handler/method is that code in?

Bob
Hi,

The code is called from the following events:-

GetData subroutine - when user selects a new datatype, the grid is populated, then the cell background color is changed according to the true/False status of the return data.

ColumnHeaderMouseClick event - when the user sorts the data by clicking on a column header, the background color status is not maitained after the sort. Therefore, the routine is called again.

I have used DGV.Visible = false before the code runs (resetting to true after completion) and this helps a little but does not solve the problem.

Regards,

Alan
Alan,

Are you using the CellPainting or CellFormatting event handlers?

Bob

Bob,

No, just the subroutines mentioned.  

I wonder if the issue is merely an artifact of the approach of checking each cell. If this is the case, I cannot see a solution other than making the gid invisible whilst the code runs, then making it visible when the process completes.  This avoids screen flicker but does result in a sudden 'jump' effect when the screen repaints the new grid.

I was hoping there was a property similar to the one in Farpoints Spread component where one could control grid updating using a simple property.

Regards,

Alan
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Bob,

Fantastic, that resolved it!

Many thanks,

Alan