I have been struggling with CellFormatting event, it's so slow.
I have a DataGridView something like this:
I have written a function that fires when you click the checkbox in the header and it makes all the check boxes to check in that column....
private void checkboxHeader_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.RowCount; i++)
{
dataGridView1[0, i].Value = ((CheckBox)dataGridView1.Controls.Find("checkboxHeader", true)[0]).Checked;
}
//dataGridView1.EndEdit();
}
And this function is working when I have something like 10 rows it works perfectly, but when I have 300 rows something that I should have... there is a something like 9 seconds delay for making all the checkboxes checked, and I found out that it's due to CellFormating event.
My CellFormating event code is:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewCellStyle _myStyle = new DataGridViewCellStyle();
int index = gdv_row.FindIndex(p => p.log == (string)dataGridView1.Rows[e.RowIndex].Cells[1].Value);
if (index != -1 && dataGridView1.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn && e.RowIndex != -1)
{
//e.CellStyle = _myStyle;
_myStyle.Font = gdv_row[index].font;
_myStyle.BackColor = gdv_row[index].backgroundcolor_color;
_myStyle.ForeColor = gdv_row[index].foregroundcolor_color;
dataGridView1.Rows[e.RowIndex].Cells[1].Style = _myStyle;
}
}
and I have used DoubleBuffering for DataGridView. Now I don't have any idea what should I do with this CellFormatting event...