Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
The datagridview is populated with data using :
C#
...
dgvMain.DataSource = dataTable;
...

I have code in dgvMain_CellMouseEnter and dgvMain_CellMouseLeave events which colours the cell you are pointing to.
This works fine when th edatagridview has small number of columns and rows.
But it seems if the datagridview is large i.e. with more columns and rows then as I move the mouse over the cells, I see flashes as if the grid is re-painting itself?
Do you know how to avoid this flashing as you are moving over cells?
Thanks

This is the kind of code I am using and does the colouring corectly.
C#
if (dgvMain[e.ColumnIndex, e.RowIndex].Style.BackColor == Color.SkyBlue)
                   {

                   }
                   else
                   {
                       dgvMain[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Gold;
                  }
Posted
Updated 19-Jul-12 1:29am
v2

One thing I can think of, although I would expect the code of the grid itself would also do this, is to keep track of the last cell that was handled by the event. Something like:

if(e.ColumnIndex != PreviousColumnIndex || e.RowIndex != PreviousRowIndex) {
// Do some coloring
}

Also, enable double buffering to prevent screen flickering:
http://stackoverflow.com/questions/118528/horrible-redraw-performance-of-the-datagridview-on-one-of-my-two-screens[^]

Good luck!
 
Share this answer
 
Hi,
It mentions the following but not sure where in the form I should place this code and what else i.e. references are required.
Can you assis please?
Thanks
C#
Here is some code that sets the property using reflection, without subclassing as Benoit suggests.
typeof(DataGridView).InvokeMember( 
   "DoubleBuffered",  
   BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, 
   null,  
   myDataGridViewObject,  
   new object[] { true }); 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900