私はCellFormattingイベントに苦労してきました、それはとても遅いです。
私は次のようなDataGridViewを持っています:
ヘッダーのチェックボックスをクリックすると起動する関数を作成しました。これにより、すべてのチェックボックスがその列にチェックインされます。
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();
}
この関数は、10行の場合は完全に機能しますが、300行の場合は、必要なものがあります...すべてのチェックボックスをオンにするのに9秒の遅延があることがわかりました。 CellFormatingイベントが原因です。
私のCellFormatingイベントコードは次のとおりです。
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;
}
}
そして私はDataGridViewにDoubleBufferingを使用しました。今、私はこのCellFormattingイベントで何をすべきか分かりません...