Search code examples
c#performancedatagridview.net-2.0windows

How do I make changing row style in a DataGridView control faster (C#)?


I have a DataGridView in a form that has a data table as the DataSource. I need to be able to change the cell style in the grid view when the user performs certain actions. The only way I've found so far is to loop through the cells and change the cell style.

This works fine, but this takes a long time. For the table I'm testing currently I have ~25 columns and it takes a second per row, which is an issue when changing the style for a lot of rows.

Is there a way to update the whole row quickly or a better way period? Is the wait caused by grid view trying to validate the data? What about it trying to update the grid visually on the fly (I tried suspending the layout of the grid during the cell update and it didn't help)?

EDIT:

Sorry, I put the wrong tags and may have left out some info. This is on a Windows desktop app using the System.Windows.Forms.DataGridView control.


Solution

  • Whole row style can be changed by using e.g. BackColor property of the row

    dataGridView.Row[index].DefaultCellStyle.BackColor = Color.Yellow