我一直在用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