我一直在用CellFormatting事件挣扎,它太慢了。C#中的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;
}
}
,我已经使用DoubleBuffering for DataGridView。现在我不知道我该如何处理这个CellFormatting事件...
SuspendLayout是要去帮助,当你添加新的你表单上的对象。根据MSDN的说法,SuspendLayout'临时挂起控件的布局逻辑.' – 2012-01-03 12:25:56
感谢您的回复,请您给出更详细的答案,或者因为我不知道如何使用此功能以及在哪里? – Ehsan 2012-01-03 12:33:41
其实我做了你所说的,但即使我看到更多的延迟,仍然有这种延迟!但我应该怎么做?你认为也许dataGridView1 [0,i]有一些错误,并使延迟?:( – Ehsan 2012-01-03 13:44:02